nginx和uWSGI会给出"504网关超时" [英] nginx and uWSGI gives "504 Gateway timeout"

查看:656
本文介绍了nginx和uWSGI会给出"504网关超时"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照教程使用uWSGI设置Django和您的Web服务器和nginx .

我将uwsgi设置为使用以下代码行服务我的Django项目.

I set up uwsgi to serve my Django project with the following line.

mydjangoproj $ uwsgi --http 0.0.0.0:8002 --module wsgi --harakiri 5

当我在浏览器中访问42.42.42.42:8002时,此方法有效.

This works when I go there in a browser, to 42.42.42.42:8002.

nginx作为守护程序运行,并且可以访问其默认站点80端口.

nginx is running as a daemon, and visiting it's default site, port 80, works.

我使用以下mydjangoproj_nginx.conf文件将其作为站点添加到了nginx:

I added this as a site to nginx using the following mydjangoproj_nginx.conf file:

server {
    listen      8000;
    server_name 42.42.42.42;
    charset     utf-8;
    client_max_body_size 75M;

    location /static {
        alias /home/myuser/mydjangoproj/static; 
    }

    location / {
        uwsgi_pass 127.0.0.1:8002;
        include     /home/myuser/mydjangoproj/uwsgi_params;
    }
}

我使用本教程的uwsgi_params的未修改版本:

I use the unmodified version of uwsgi_params, from the tutorial:

uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;

它确实可以完美地服务于静态文件.

It does serve the static files perfectly.

如果我访问42.42.42.42:8000,它将挂起很长时间,直到我猜到nginx超时,然后得到504 Gateway Time-out.

If I visit 42.42.42.42:8000 it hangs for a long time, until the nginx timeout I guess, and I get 504 Gateway Time-out.

uWSGI在shell中什么也不写.如果直接在浏览器中访问,它确实会写有关接收请求的信息.

uWSGI writes nothing in the shell. If visiting directly in browser, it does write about receiving a request.

仅在超时后才写入nginx错误日志:

The nginx error log writes, only after the timeout:

2014/12/11 05:31:12 [error] 28895#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 66.66.66.66, server: 42.42.42.42, request: "GET / HTTP/1.1", upstream: "uwsgi://42.42.42.42:8002", host: "42.42.42.42:8000"

如果我关闭从外壳程序运行的uWSGI,我会立即得到一个502 Bad Gateway.

If I close the uWSGI, which is just run from a shell, I instantly get a 502 Bad Gateway.

在线搜索时,人们只建议将uWSGI超时设置为低于nginx超时,这就是为什么我要使用--harakiri 5运行uWSGI的原因.

When searching online, people just recommend setting the uWSGI timeout lower than the nginx timeout, that's why I run uWSGI with --harakiri 5.

那么,我在这里有什么问题?

So, what is my problem here?

推荐答案

我认为您正在以http模式--http 0.0.0.0:8002运行uwsgi,但是您已将nginx配置为wsgi代理,将uwsgi脚本更改为:

I think you are running uwsgi in http mode --http 0.0.0.0:8002 but you have configured nginx as wsgi proxy change your uwsgi script as:

 uwsgi --socket :8002 --module wsgi --harakiri 5

请注意,如果您在同一台计算机上运行nginxuwsgi,最好使用

Note that if you are running nginx and uwsgi on the same machine is better to use unix sockets

这篇关于nginx和uWSGI会给出"504网关超时"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆