nginx 的配置文件:
server {
    listen         80;
    server_name    127.0.0.1
    charset UTF-8;
    access_log      /var/log/nginx/myweb_access.log;
    error_log       /var/log/nginx/myweb_error.log;
    client_max_body_size 75M;
    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:8023;
        uwsgi_read_timeout 2;
    }
    location /static {
        expires 30d;
        autoindex on;
        add_header Cache-Control private;
        alias /home/work/JZAssist/collected_static/;
     }
 }
我的 supervisord 中的 command 是
command=uwsgi --http :8023 --chdir /home/work/xxxx --module xxxx.wsgi
xxxx 是项目名称。 问题是可以通过域名加端口访问,但是直接用域名访问就出现 504 Gateway Time-out 。我重装过 nginx,但看起来好像并不是 nginx 的问题。
|      1hcymk2      2017-02-26 13:43:50 +08:00 uwsgi_read_timeout  好像小了点 | 
|  |      2cnZary      2017-02-26 13:57:58 +08:00 你域名解析到哪个 ip ? 是不是没监听到.... | 
|  |      3xyxc0673 OP @linzianplay 就只有一个 ip 。为什么域名加端口就可以访问? | 
|  |      5alect      2017-02-26 14:09:54 +08:00 via Android sever name 不应该是写域名么? | 
|      6Yourdaye      2017-02-26 14:10:41 +08:00 https://www.v2ex.com/t/339602#reply19  换 gunicorn | 
|  |      9orzfly      2017-02-26 14:34:42 +08:00  1 你的 uwsgi 好像是开了个 8023 的 HTTP 端口,你 nginx 居然尝试用 uswsgi 协议连? include uwsgi_params; uwsgi_pass 127.0.0.1:8023; uwsgi_read_timeout 2; 把 uwsgi 换成 proxy 吧,你这个需要用 proxy_pass 127.0.0.1:8023; | 
|  |      10freestyle      2017-02-26 15:16:34 +08:00 如果 nginx 配置上写的是 uwsgi_pass  那么 uwsgi 启动的命令行参数应该写成 socket 而不是 http command=uwsgi --socket :8023 --chdir /home/work/xxxx --module xxxx.wsgi | 
|  |      11xyxc0673 OP | 
|      12Lax      2017-02-26 16:52:06 +08:00 via iPad 不贴日志都能猜出来,服你们! | 
|  |      13est      2017-02-26 16:58:01 +08:00 server { listen 80; server_name 127.0.0.1 .... } 这三行的意思可能 LZ 没懂,我帮你翻译一下:只有 http://127.0.0.1:80/ 这种形式的网址才能被这个 server { } 块里的配置匹配到。 如果你配置了个域名,不知道你的 server_name 飞到什么鬼地方去了。 | 
|      15anonymalias      2017-02-27 16:47:46 +08:00 @est 你应该好好看看 nignx 文档:“ If a server is the only server for a listen port, then nginx will not test server names at all (and will not build the hash tables for the listen port). However, there is one exception. If a server name is a regular expression with captures, then nginx has to execute the expression to get the captures.” | 
|  |      16est      2017-02-27 20:41:47 +08:00 @anonymalias 你觉得 LZ 这配置就是你贴文档里所说的 the only server 么。 | 
|  |      17AyoCross      2017-02-27 22:54:14 +08:00 我记得当时我在部署 django+uWSGI+Nginx 的时候也出现过这个问题,但最后是怎么解决的有些忘了。。你看一下官方文档步骤,再重来一遍: http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html | 
|  |      18xingzhi      2017-03-05 13:41:52 +08:00 这个可以作为面试题,挺好的。 |