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

django+uwsgi+nginx 出现问题

  •  
  •   ffx0s · 2015-02-20 13:12:16 +08:00 · 12344 次点击
    这是一个创建于 3592 天前的主题,其中的信息可能已经有所发展或是发生改变。

    web页面出现Internal Server Error,查看错误日志提示: 2015/02/18 19:51:12 [error] 810#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: xx.xx.xx.xx, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8000", host: "xx.xx.xx.xx"。求解所方法。

    31 条回复    2015-04-03 00:23:05 +08:00
    dingyaguang117
        1
    dingyaguang117  
       2015-02-20 14:15:56 +08:00
    uwsgi配置贴一下
    surefire
        2
    surefire  
       2015-02-20 15:22:33 +08:00
    8000端口没开吧
    ffx0s
        3
    ffx0s  
    OP
       2015-02-20 15:28:36 +08:00
    @surefire 开了。
    tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
    ffx0s
        4
    ffx0s  
    OP
       2015-02-20 15:29:56 +08:00
    server {

    listen 80;
    server_name 121.40.90.156;
    access_log /mydata/www/log/access.log;
    error_log /mydata/www/log/error.log;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root /mydata/www;
    include uwsgi_params;
    # uwsgi_pass 127.0.0.1:9090;
    uwsgi_pass 127.0.0.1:8000;
    # uwsgi_param UWSGI_PYHOME /mydata/www/;
    # uwsgi_param UWSGI_SCRIPT /mydata/www/;
    # uwsgi_param UWSGI_CHDIR /mydata/www/;
    }

    #error_page 404 /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    location /static/ {
    alias /mydata/www/kisspy/static/;
    index index.html index.htm;
    }

    location /media/ {
    alias /mydata/www/kisspy/static/media/;
    }
    }
    ffx0s
        5
    ffx0s  
    OP
       2015-02-20 15:32:37 +08:00
    @dingyaguang117
    <uwsgi>
    <socket>127.0.0.1:8000</socket>
    <listen>80</listen>
    <master>true</master>
    <pidfile>/var/run/nginx.pid</pidfile>
    <processes>8</processes>
    <pythonpath>/mydata/www</pythonpath>
    <module>wsgi</module>
    <profiler>true</profiler>
    <memory-report>true</memory-report>
    <enable-threads>true</enable-threads>
    <logdate>true</logdate>
    <limit-as>300</limit-as>
    <daemonize>/mydata/www/log/django.log</daemonize>
    </uwsgi>
    imlonghao
        6
    imlonghao  
       2015-02-20 15:37:56 +08:00 via Android
    <listen>80</listen>
    ffx0s
        7
    ffx0s  
    OP
       2015-02-20 15:38:21 +08:00
    主机是阿里云的。奇怪的是把磁盘快照回滚到环境部署好的。还是会出现这个问题。
    imlonghao
        8
    imlonghao  
       2015-02-20 15:43:37 +08:00 via Android
    <pidfile>/var/run/nginx.pid</pidfile>
    <listen>80</listen>

    uwsgi的配置为什么要这样写?
    imlonghao
        9
    imlonghao  
       2015-02-20 15:52:17 +08:00 via Android
    贴一下uwsgi的配置看看?
    imlonghao
        10
    imlonghao  
       2015-02-20 15:52:31 +08:00 via Android
    更正,日志
    imlonghao
        11
    imlonghao  
       2015-02-20 15:53:00 +08:00 via Android
    /mydata/www/log/django.log
    tonghuashuai
        12
    tonghuashuai  
       2015-02-20 16:06:24 +08:00
    <daemonize>/mydata/www/log/django.log</daemonize> 这个地方用 uwsgi 自己的日志文件
    <pidfile>/var/run/nginx.pid</pidfile> 这个地方不应该用 nginx.pid
    ffx0s
        13
    ffx0s  
    OP
       2015-02-20 18:21:29 +08:00
    @tonghuashuai <pidfile>/var/run/nginx.pid</pidfile>用什么?
    ffx0s
        14
    ffx0s  
    OP
       2015-02-20 18:22:32 +08:00
    @imlonghao
    django.log: {address space usage: 14348288 bytes/13MB} {rss usage: 4497408 bytes/4MB} [pid: 1340|app: -1|req: -1/22] 101.233.154.251 () {42 vars in 657 bytes} [Fri Feb 20 16:22:58 2015] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
    Fri Feb 20 16:22:59 2015 - --- no python application found, check your startup logs for errors ---
    {address space usage: 14348288 bytes/13MB} {rss usage: 4497408 bytes/4MB} [pid: 1345|app: -1|req: -1/23] 101.233.154.251 () {44 vars in 737 bytes} [Fri Feb 20 16:22:59 2015] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
    Fri Feb 20 16:22:59 2015 - --- no python application found, check your startup logs for errors ---
    {address space usage: 14348288 bytes/13MB} {rss usage: 4497408 bytes/4MB} [pid: 1347|app: -1|req: -1/24] 101.233.154.251 () {42 vars in 657 bytes} [Fri Feb 20 16:22:59 2015] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
    dingyaguang117
        15
    dingyaguang117  
       2015-02-20 19:01:02 +08:00 via iPhone
    汗,楼主从哪儿抄的配置
    msg7086
        16
    msg7086  
       2015-02-20 19:11:46 +08:00 via iPhone
    <socket>127.0.0.1:8000</socket>
    <listen>80</listen>
    <pidfile>/var/run/nginx.pid</pidfile>
    我一个不懂python的人都知道这3句都有问题。
    imlonghao
        17
    imlonghao  
       2015-02-20 19:34:30 +08:00
    @msg7086 <socket>127.0.0.1:8000</socket> 这个是没问题的,不过下面两句真的不敢恭维
    imlonghao
        18
    imlonghao  
       2015-02-20 19:37:11 +08:00
    no python application found, check your startup logs for errors
    imlonghao
        19
    imlonghao  
       2015-02-20 19:45:17 +08:00
    我有理由相信你的 <module>wsgi</module> 配置错误

    这是我的配置文件,您可以参考一下
    https://github.com/esdcc/esd.cc/blob/master/esdcc.xml#L6
    这一行所写的 ·wsgi· 对应的是 https://github.com/esdcc/esd.cc/blob/master/wsgi.py

    测试如下,我将我的这个配置改成·<module>1213wsgi</module>· (一个没有对应文件的)
    出现了和你类似的问题

    500


    Log
    imlonghao
        20
    imlonghao  
       2015-02-20 19:51:08 +08:00
    Log
    ffx0s
        21
    ffx0s  
    OP
       2015-02-20 20:41:19 +08:00
    @imlonghao 头疼。。服务器一些配置不怎么会,这些配置就是网上找的,话说python也只是刚开始学,还是得继续努力,谢谢你了。
    ffx0s
        22
    ffx0s  
    OP
       2015-02-20 20:45:47 +08:00
    @dingyaguang117 配置网上找的。对python感兴趣就学了。其实我是前端。。
    ffx0s
        23
    ffx0s  
    OP
       2015-02-20 20:47:09 +08:00
    @dingyaguang117 网上抄的。
    imlonghao
        24
    imlonghao  
       2015-02-20 21:29:00 +08:00
    tonghuashuai
        25
    tonghuashuai  
       2015-02-21 09:39:51 +08:00
    @ffx0s 新建一个 uwsgi.pid
    surefire
        26
    surefire  
       2015-02-22 17:22:20 +08:00
    lsdvincent
        27
    lsdvincent  
       2015-02-22 18:57:44 +08:00
    胆战心惊贴个自己的Blog http://blog.breakwire.me/blog/20150208/ 绝对跑得起来,跑不起来楼主凑我!
    tolerious
        28
    tolerious  
       2015-03-02 09:55:54 +08:00 via iPhone
    把listen那个去掉,不是已经8000端口转发了么?
    1130335361
        29
    1130335361  
       2015-04-02 22:42:06 +08:00
    @lsdvincent 1.logs下面的access.log和error.log是文件还是文件夹?2.需要自己建立吗
    lsdvincent
        30
    lsdvincent  
       2015-04-03 00:22:25 +08:00 via iPhone
    @1130335361 是文件;logs 文件夹要自己建立
    lsdvincent
        31
    lsdvincent  
       2015-04-03 00:23:05 +08:00 via iPhone
    @lsdvincent 只要建那个logs文件夹就行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2707 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 06:01 · PVG 14:01 · LAX 22:01 · JFK 01:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.