作者: | 来源:互联网 | 2023-08-31 14:44
第一遍这么输入的:uwsgi --socket :8001 --wsgi-file test.py
没有问题
第二遍输入:uwsgi --socket mysite.sock --wsgi-file test.py
就不对了
bind(): Operation not permitted [core/socket.c line 230]
第二遍用新的参数重新启动uwsgi的时候出上面的报错
uwsgi --socket mysite.sock --wsgi-file test.py --chmod-socket=666
这样也不行
项目文件夹的读写权限如下:
drwxr-xr-x 1 vagrant vagrant 374 Feb 3 07:32 mysite/
显然写权限只属于vagrant用户。
那么我是否把整个项目文件夹的写权限全部允许给uwsgi就可以了?
Using Unix sockets instead of ports
So far we have used a TCP port socket, because it’s simpler, but in fact it’s better to use Unix sockets than ports - there’s less overhead.
Edit mysite_nginx.conf, changing it to match:
1 2
| server unix:///path/to/your/mysite/mysite.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first) and restart nginx. |
Run uWSGI again:
1
| uwsgi --socket mysite.sock --wsgi-file test.py |
This time the socket option tells uWSGI which file to use.
Try http://example.com:8000/ in the browser.
If that doesn’t work
Check your nginx error log(/var/log/nginx/error.log). If you see something like:
1
| connect() to unix:///path/to/your/mysite/mysite.sock failed (13: Permission denied) |
then probably you need to manage the permissions on the socket so that nginx is allowed to use it.
Try:
1
| uwsgi --socket mysite.sock --wsgi-file test.py --chmod-socket=666 # (very permissive) |
or:
1
| uwsgi --socket mysite.sock --wsgi-file test.py --chmod-socket=664 # (more sensible) |
You may also have to add your user to nginx’s group (which is probably www-data), or vice-versa, so that nginx can read and write to your socket properly.
It’s worth keeping the output of the nginx log running in a terminal window so you can easily refer to it while troubleshooting.