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
waterlaw
V2EX  ›  Python

Nginx 报 500 号错误

  •  
  •   waterlaw ·
    water-law · 2018-01-15 18:01:16 +08:00 · 2756 次点击
    这是一个创建于 2502 天前的主题,其中的信息可能已经有所发展或是发生改变。

    服务端采用 Django + Nginx + Gunicorn 部署, 每次访问 /articles/{id} 这个接口时就报 500/502/504 错误。nginx 错误文件:

    2018/01/15 16:49:44 [error] 1006#1006: *1274 upstream prematurely closed connection while reading response header from upstream, client: 27.154.27.176, server: waterlaw.cn, request: "GET /articles/6 HTTP/1.1", upstream: "http://unix:/tmp/waterlaw.cn.socket:/articles/6", host: "waterlaw.cn", referrer: "https://waterlaw.cn/"
    2018/01/15 17:07:17 [error] 1006#1006: *1338 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 27.154.27.176, server: waterlaw.cn, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/waterlaw.cn.socket:/", host: "waterlaw.cn"
    2018/01/15 17:10:47 [error] 22126#22126: *7 upstream prematurely closed connection while reading response header from upstream, client: 27.154.225.154, server: waterlaw.cn, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/waterlaw.cn.socket:/", host: "waterlaw.cn"
    2018/01/15 17:14:26 [error] 22236#22236: *8 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 27.154.225.154, server: waterlaw.cn, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/waterlaw.cn.socket/", host: "waterlaw.cn"
    2018/01/15 17:16:03 [error] 22236#22236: *8 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 27.154.225.154, server: waterlaw.cn, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/waterlaw.cn.socket/", host: "waterlaw.cn"
    2018/01/15 17:43:44 [error] 22615#22615: *1 upstream prematurely closed connection while reading response header from upstream, client: 27.154.27.176, server: waterlaw.cn, request: "GET /articles/6 HTTP/1.1", upstream: "http://unix:/tmp/waterlaw.cn.socket:/articles/6", host: "waterlaw.cn", referrer: "https://waterlaw.cn/"
    
    
    

    Gunicorn 控制台的错误日志:

    [2018-01-15 17:51:19 +0800] [22183] [CRITICAL] WORKER TIMEOUT (pid:22730)
    
    7 条回复    2018-01-16 19:37:11 +08:00
    alect
        1
    alect  
       2018-01-15 19:34:50 +08:00
    upstream 设置的不对吧
    Beebird
        2
    Beebird  
       2018-01-15 19:47:30 +08:00
    django 有日志输出吗? 有条件的话试试直接访问 django 的监听端口
    beiposhiming
        3
    beiposhiming  
       2018-01-15 20:20:55 +08:00 via iPad
    想花式 500 ?
    你得跟着 V2EX 多学学😂
    flipped123
        4
    flipped123  
       2018-01-16 09:14:27 +08:00
    排查两方面,一个关闭防火墙试试,同时注意关闭 selinux 试试。
    zpfhbyx
        5
    zpfhbyx  
       2018-01-16 09:37:07 +08:00
    http://unix:/... 肯定连不上啊。。
    xia0pia0
        6
    xia0pia0  
       2018-01-16 10:05:37 +08:00
    proxy_pass 配错了吧,upstream 那块的问题
    waterlaw
        7
    waterlaw  
    OP
       2018-01-16 19:37:11 +08:00 via Android
    不知道是不是文件句柄太多, 每次修改完都再次开启 gunicorn, 然后开了多个进程。 重启一下突然好了, 想到博客用了结巴分词, 然后缓存的时候占用了 1.5 秒。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1166 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 18:09 · PVG 02:09 · LAX 10:09 · JFK 13:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.