当前位置: 首页 > article >正文

Nginx报错合集(502 Bad Gateway,504 Gateway nginx/1.18.0 (Ubuntu) 等等报错)

1.504 Gateway Time-outnginx/1.18.0 (Ubuntu)

日志报错:

2024/02/11 04:38:54 [error] 564#564: *29 
upstream timed out (110: Connection timed out) 
while reading response header from upstream, 
client: *******, 
server: *******, 
request: "GET /favicon.ico HTTP/1.1", 
upstream: "http://unix:/home/*******/myproject/app.sock/favicon.ico", 
host: "*******", 
referrer: "http://*******/"

应用服务器(通过 app.sock Unix 套接字)获取 /favicon.ico 时遇到了超时问题。

这通常表明请求没有被正确地路由到静态文件处理逻辑,而是被发送到了后端应用,

后端应用没有及时响应或无法处理该请求

解决方法:说明favicon.ico的位置

    location = /favicon.ico {
        alias /home/*****/myproject/static/favicon.ico;
        access_log off;
        log_not_found off;
    }

2.502 Bad Gateway   nginx/1.18.0 (Ubuntu):

日志报错:

2024/02/11 05:08:04 [crit] 12048#12048:
 *4 connect() to unix:/home/********/myproject/app.sock 
failed (2: No such file or directory) while connecting to upstream, 
client: ********, 
server: ********,
request: "GET / HTTP/1.1", 
upstream: "http://unix:/home/********/myproject/app.sock:/", 
host: "********"

这个错误表明 Nginx 无法通过 Unix 套接字 app.sock 连接到您的应用程序,因为它找不到指定的文件或目录。可能的原因包括:

  • 1.应用程序未运行:如果您的应用程序没有启动,那么 .sock 文件也不会存在。

  • 2.路径错误:配置中的路径不正确,或 .sock 文件被移动或删除。

  • 3.权限问题:Nginx 没有足够的权限访问 .sock 文件。

解决方法:

原因一:

查看gunicorn的状态:
sudo systemctl status myproject
如下状态(截取网上): 
gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-01-18 23:32:11 UTC; 3min 23s ago
  Process: 6347 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 6355 (gunicorn)
    Tasks: 2
   Memory: 195.7M
      CPU: 1.426s
   CGroup: /system.slice/gunicorn.service
           ├─6355 /srv/venvs/myenv/bin/python3.6 /srv/venvs/myenv/bin/gunicorn --pid /run/gunicorn/pid --bind unix:/run/gunicorn/socket myapp.wsgi:application
           └─6360 /srv/venvs/myenv/bin/python3.6 /srv/venvs/myenv/bin/gunicorn --pid /run/gunicorn/pid --bind unix:/run/gunicorn/socket myapp.wsgi:application

Jan 18 23:32:11 python-server systemd[1]: Stopped gunicorn daemon.
Jan 18 23:32:11 python-server systemd[1]: Started gunicorn daemon.
Jan 18 23:32:11 python-server gunicorn[6355]: [2018-01-18 23:32:11 +0000] [6355] [INFO] Starting gunicorn 19.7.1
Jan 18 23:32:11 python-server gunicorn[6355]: [2018-01-18 23:32:11 +0000] [6355] [INFO] Listening at: unix:/run/gunicorn/socket (6355)
Jan 18 23:32:11 python-server gunicorn[6355]: [2018-01-18 23:32:11 +0000] [6355] [INFO] Using worker: sync
Jan 18 23:32:11 python-server gunicorn[6355]: [2018-01-18 23:32:11 +0000] [6360] [INFO] Booting worker with pid: 6360
 若出现任何error或者warning,请修复他之后运行以下命令
(重新加载gunicorn,并查看状态):
pkill gunicorn
sudo systemctl daemon-reload
sudo systemctl start myproject
sudo systemctl enable myproject
sudo systemctl status myproject

原因二:修改权限(前面为用户名,后面为路径)

sudo chown ******:www-data /home/****/*****/


http://www.kler.cn/news/235040.html

相关文章:

  • 第三节 zookeeper基础应用与实战2
  • springboot181基于springboot的乐享田园系统
  • 【AIGC风格prompt深度指南】掌握绘画风格关键词,实现艺术模仿的革新实践
  • AutoSAR(基础入门篇)7.3-使用DEV配置SWCRTE
  • Visual Studio使用Git忽略不想上传到远程仓库的文件
  • 假期刷题打卡--Day26
  • 品牌如何营造生活感氛围?媒介盒子分享
  • 2024-02-11 Unity 编辑器开发之编辑器拓展2 —— 自定义窗口
  • 【JavaEE Spring 项目】博客系统
  • django密码管理器(创建项目)
  • 使用C++从零开始,自己写一个MiniWeb
  • Python在金融大数据分析中的AI应用实战
  • JavaScript学习之旅10------掌握jQuery:实用应用案例深度解析
  • 【深度学习 目标检测】R-CNN系列算法全面概述(一文搞懂R-CNN、Fast R-CNN、Faster R-CNN的来龙去脉)
  • tab 切换类交互功能实现
  • C语言每日一题(55)另一颗树的子树
  • 《UE5_C++多人TPS完整教程》学习笔记5 ——《P6 在线子系统(Online Subsystem)》
  • [算法学习] 唯一分解定理
  • 批量提取word文件中文本框内容的三种方法
  • Go基础学习笔记-知识点
  • 速盾:怎么拿高防服务器做CDN
  • springBoot,springSecurity返回乱码
  • Linux系统调试课:Linux错误码介绍
  • system V——进程间通信
  • 大模型学习 一
  • 软件架构与系统架构:区别与联系的分析
  • 跟踪分析一款新型Megahorse窃密木马
  • RabbitMQ之五种消息模型
  • 一、基础数据结构——2.队列——3.双端队列和单调队列2
  • 学习Android的第十天