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

[求助]ubuntu Nginx uwsgi 配置: 使用 uwsgi --http 可以, 使用 uwsgi --socket 是无法连接到服务器

  •  
  •   myxinn · 2018-04-11 02:56:23 +08:00 · 3609 次点击
    这是一个创建于 2179 天前的主题,其中的信息可能已经有所发展或是发生改变。

    按着文档 https://uwsgi.readthedocs.io/en/latest/tutorials/Django_and_nginx.html 做的

    uwsgi --http :8000 --wsgi-file test.py
    

    可以显示

     uwsgi --socket :8001 --wsgi-file test.py 
    

    无法连接服务器

    uwsgi log:

    (venv) ubuntu@VM-49-116-ubuntu:~/code/blog/mmxy$ uwsgi --socket :8001 --wsgi-file test.py
    *** Starting uWSGI 2.0.17 (64bit) on [Wed Apr 11 02:19:40 2018] ***
    compiled with version: 5.4.0 20160609 on 09 April 2018 17:37:14
    os: Linux-4.4.0-91-generic #114-Ubuntu SMP Tue Aug 8 11:56:56 UTC 2017
    nodename: VM-49-116-ubuntu
    machine: x86_64
    clock source: unix
    detected number of CPU cores: 1
    current working directory: /home/ubuntu/code/blog/mmxy
    detected binary path: /home/ubuntu/code/blog/venv/bin/uwsgi
    !!! no internal routing support, rebuild with pcre support !!!
    *** WARNING: you are running uWSGI without its master process manager ***
    your processes number limit is 3306
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    thunder lock: disabled (you can enable it with --thunder-lock)
    uwsgi socket 0 bound to TCP address :8001 fd 3
    Python version: 3.6.4 (default, Apr 10 2018, 00:02:46)  [GCC 5.4.0 20160609]
    *** Python threads support is disabled. You can enable it with --enable-threads ***
    Python main interpreter initialized at 0xe92290
    your server socket listen backlog is limited to 100 connections
    your mercy for graceful operations on workers is 60 seconds
    mapped 72920 bytes (71 KB) for 1 cores
    *** Operational MODE: single process ***
    WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xe92290 pid: 8870 (default app)
    *** uWSGI is running in multiple interpreter mode ***
    spawned uWSGI worker 1 (and the only) (pid: 8870, cores: 1)
    

    nginx 配置 mysite_nginx.conf

        upstream django {
            # server unix:///tmp/mmxy.sock;
            server 127.0.0.1:8001; # for a web port socket (we'll use this first)
        }
        
        
        server {
        
            listen      8000;
            server_name 140.143.242.243;
            # server_name sususuus.xyz;
            charset     utf-8;
        
            access_log /var/log/nginx/access.log;
            error_log /var/log/nginx/error.log;
        
            # max upload size
            client_max_body_size 75M;   # adjust to taste
        
            # Django media
            location /media  {
                alias /home/ubuntu/code/blog/mmxy/media;
            }
        
            location /static {
                alias /home/ubuntu/code/blog/mmxy/static;
            }
        
            # Finally, send all non-media requests to the Django server.
            location / {
                uwsgi_pass  django;
                include     /etc/nginx/uwsgi_params;
            }
        }
    
    

    直接访问服务器, 有 Nginx 的欢迎界面

    尝试给 uwsgi --socket :8001 --wsgi-file test.py 加一些参数 --protocol=http -b 30000 limit 128 都是无法连接服务器

    nginx 下的 /var/log/nginx/error.log 是个空文件, 不知道为什么

    尝试了各种办法, 重装了两次系统了, /(ㄒoㄒ)/~~

    coffeSlider
        1
    coffeSlider  
       2018-04-11 09:00:47 +08:00 via Android
    一言不合就重装系统.....
    你看看 Nginx 日志,

    没记错的话,
    应该是 socket 包大小限制了。
    MonoBiao
        2
    MonoBiao  
       2018-04-11 10:51:43 +08:00
    用 socket 文件进行通信呢?
    julyclyde
        3
    julyclyde  
       2018-04-11 13:11:27 +08:00
    “无法连接服务器”是浏览器给出的提示(浏览器无法连接 nginx )
    还是 nginx 给出的提示( nginx 无法连接 uwsgi )
    myxinn
        4
    myxinn  
    OP
       2018-04-11 15:23:51 +08:00
    @coffeSlider
    Nginx 没有错误日志 🤔🤔🤔
    `
    access.log
    223.72.97.144 - - [11/Apr/2018:11:06:17 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5"
    223.72.97.144 - - [11/Apr/2018:11:06:21 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5"
    ^[[A^C
    (venv) ubuntu@VM-49-116-ubuntu:/var/log/nginx$ tail -10f error.log
    ^C
    (venv) ubuntu@VM-49-116-ubuntu:/var/log/nginx$ ll error.log
    -rw-r----- 1 www-data adm 0 Apr 10 01:45 error.log
    `

    解决了, 通过 sudo nginx -t 测试 Nginx:
    Nginx 的 error.log 无权限, /var/nginx/pid 无权限
    都给了个 664 权限,
    不知道为什么, Nginx 的 access.log 可以, error.log 却没权限
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5304 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 05:57 · PVG 13:57 · LAX 22:57 · JFK 01:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.