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

2018-04-11 02:56:23 +08:00
 myxinn

按着文档 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ㄒ)/~~

3826 次点击
所在节点    Python
4 条回复
coffeSlider
2018-04-11 09:00:47 +08:00
一言不合就重装系统.....
你看看 Nginx 日志,

没记错的话,
应该是 socket 包大小限制了。
MonoBiao
2018-04-11 10:51:43 +08:00
用 socket 文件进行通信呢?
julyclyde
2018-04-11 13:11:27 +08:00
“无法连接服务器”是浏览器给出的提示(浏览器无法连接 nginx )
还是 nginx 给出的提示( nginx 无法连接 uwsgi )
myxinn
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 却没权限

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

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

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

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

© 2021 V2EX