可以通过域名加端口访问,但是直接用域名访问就 504 Gateway Time-out

2017-02-26 13:36:16 +08:00
 xyxc0673

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 的问题。

5917 次点击
所在节点    Python
18 条回复
hcymk2
2017-02-26 13:43:50 +08:00
uwsgi_read_timeout 好像小了点
cnZary
2017-02-26 13:57:58 +08:00
你域名解析到哪个 ip ?
是不是没监听到....
xyxc0673
2017-02-26 14:06:20 +08:00
@linzianplay 就只有一个 ip 。为什么域名加端口就可以访问?
xyxc0673
2017-02-26 14:06:50 +08:00
@hcymk2 之前设置成这样也没问题。
alect
2017-02-26 14:09:54 +08:00
sever name 不应该是写域名么?
Yourdaye
2017-02-26 14:10:41 +08:00
xyxc0673
2017-02-26 14:19:16 +08:00
@alect 可以这样写吧。
xyxc0673
2017-02-26 14:20:09 +08:00
@Yourdaye 如果实在不行就换 gunicorn ,之前也是这样配置,都没有问题。
orzfly
2017-02-26 14:34:42 +08:00
你的 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;
freestyle
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
xyxc0673
2017-02-26 16:34:11 +08:00
@orzfly
@freestyle
确实和你们说的一样。
可能我在配置的时候有点混乱,然后把不同操作的命令混进来了。
谢谢!!!
Lax
2017-02-26 16:52:06 +08:00
不贴日志都能猜出来,服你们!
est
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 飞到什么鬼地方去了。
xyxc0673
2017-02-26 18:51:15 +08:00
@est 看来还要系统学习下才行。谢谢啦。
anonymalias
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.”
est
2017-02-27 20:41:47 +08:00
@anonymalias 你觉得 LZ 这配置就是你贴文档里所说的 the only server 么。
AyoCross
2017-02-27 22:54:14 +08:00
我记得当时我在部署 django+uWSGI+Nginx 的时候也出现过这个问题,但最后是怎么解决的有些忘了。。你看一下官方文档步骤,再重来一遍: http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
xingzhi
2017-03-05 13:41:52 +08:00
这个可以作为面试题,挺好的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/343253

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX