V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
xyxc0673
V2EX  ›  Python

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

  •  
  •   xyxc0673 ·
    xyxc0673 · 2017-02-26 13:36:16 +08:00 · 5909 次点击
    这是一个创建于 2608 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    18 条回复    2017-03-05 13:41:52 +08:00
    hcymk2
        1
    hcymk2  
       2017-02-26 13:43:50 +08:00
    uwsgi_read_timeout 好像小了点
    cnZary
        2
    cnZary  
       2017-02-26 13:57:58 +08:00
    你域名解析到哪个 ip ?
    是不是没监听到....
    xyxc0673
        3
    xyxc0673  
    OP
       2017-02-26 14:06:20 +08:00
    @linzianplay 就只有一个 ip 。为什么域名加端口就可以访问?
    xyxc0673
        4
    xyxc0673  
    OP
       2017-02-26 14:06:50 +08:00
    @hcymk2 之前设置成这样也没问题。
    alect
        5
    alect  
       2017-02-26 14:09:54 +08:00 via Android
    sever name 不应该是写域名么?
    Yourdaye
        6
    Yourdaye  
       2017-02-26 14:10:41 +08:00
    xyxc0673
        7
    xyxc0673  
    OP
       2017-02-26 14:19:16 +08:00
    @alect 可以这样写吧。
    xyxc0673
        8
    xyxc0673  
    OP
       2017-02-26 14:20:09 +08:00
    @Yourdaye 如果实在不行就换 gunicorn ,之前也是这样配置,都没有问题。
    orzfly
        9
    orzfly  
       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;
    freestyle
        10
    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
        11
    xyxc0673  
    OP
       2017-02-26 16:34:11 +08:00
    @orzfly
    @freestyle
    确实和你们说的一样。
    可能我在配置的时候有点混乱,然后把不同操作的命令混进来了。
    谢谢!!!
    Lax
        12
    Lax  
       2017-02-26 16:52:06 +08:00 via iPad
    不贴日志都能猜出来,服你们!
    est
        13
    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
        14
    xyxc0673  
    OP
       2017-02-26 18:51:15 +08:00
    @est 看来还要系统学习下才行。谢谢啦。
    anonymalias
        15
    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
        16
    est  
       2017-02-27 20:41:47 +08:00
    @anonymalias 你觉得 LZ 这配置就是你贴文档里所说的 the only server 么。
    AyoCross
        17
    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
        18
    xingzhi  
       2017-03-05 13:41:52 +08:00
    这个可以作为面试题,挺好的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4750 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:52 · PVG 17:52 · LAX 02:52 · JFK 05:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.