简体   繁体   English

Nginx (proxy_pass) + Gunicorn 无法到达

[英]Nginx (proxy_pass) + Gunicorn can’t be reached

I want to run django with gunicorn and nginx as a proxy server on a remote Ubuntu VPS.我想在远程 Ubuntu VPS 上使用 gunicorn 和 nginx 作为代理服务器运行 django。

The site works with djangos dev server :该站点与djangos 开发服务器一起使用:

python manage.py runserver 0.0.0.0:8000

The site works with gunicorns server (even static files don't work):该站点与gunicorns 服务器一起使用(即使 static 文件也不起作用):

gunicorn my_project.wsgi --bind 0.0.0.0:8000

But with nginx on top I get the following error:但是在顶部使用nginx时,我收到以下错误:

This site can't be reached... refused to connect.无法访问此站点...拒绝连接。 ERR_CONNECTION_REFUSED ERR_CONNECTION_REFUSED

Also both nginx log files error.log & access.log are empty. nginx 日志文件error.logaccess.log也是空的。

Here is how I configured nginx:以下是我配置 nginx 的方法:

server {
        listen 80;

        server_name my_ip_address;

        location / {
            proxy_pass http://127.0.0.1:8001;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Scheme $scheme;
        }
} 

In this case gunicorn runs with --bind 127.0.0.1:8001 of course.在这种情况下, gunicorn 当然使用--bind 127.0.0.1:8001运行。

Status check ( service nginx status ) returns:状态检查( service nginx status )返回:

● nginx.service - A high performance web server and a reverse proxy server
Active: active (running) since Fri 2019-09-20 07:41:00 UTC; 1min 19s ago
Starting A high performance web server and a reverse proxy server...
nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Started A high performance web server and a reverse proxy server.

First, check your configuration with nginx -t .首先,使用nginx -t检查您的配置。 The configuration you posted is not valid as a standalone config file, but I assume you are using the common nginx config structure of having a main nginx.conf and sites-available and sites-enabled directories.您发布的配置作为独立配置文件无效,但我假设您使用的是常见的 nginx 配置结构,该结构具有主要的nginx.confsites-availablesites-enabled目录。

If it does not complain, introduce an error, eg by removing a closing bracket, and try again.如果它没有抱怨,引入一个错误,例如通过删除一个右括号,然后再试一次。 If it still doesn't complain, your configuration is not being picked up by nginx.如果它仍然没有抱怨,则 nginx 没有拾取您的配置。

In this case, check if you created a correct symlink from sites-enabled/your_config to sites-available/your_config .在这种情况下,请检查您是否创建了从sites-enabled/your_configsites-available/your_config的正确符号链接。

If that all seems correct:如果这一切看起来都是正确的:

  • check if nginx is actually running: ps aux | grep nginx检查 nginx 是否实际运行: ps aux | grep nginx ps aux | grep nginx
  • check if nginx is listening to port 80: netstat -tulpen | grep ":80"检查 nginx 是否正在监听端口 80: netstat -tulpen | grep ":80" netstat -tulpen | grep ":80"
  • check firewall rules检查防火墙规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM