将uwsgi配置参数从端口号改为socket文件,需要给uwsgi哪些权限?
第一遍这么输入的: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:
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:
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:
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:
uwsgi --socket mysite.sock --wsgi-file test.py --chmod-socket=666 # (very permissive)
or:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
uwsgi 需要对你指定的 socket 文件所在的目录有写权限,这样才能成功创建 socket 文件。你可以为 uwsgi 专门建个目录,也可以把 socket 放到比如 /var/run 或者 /tmp 下。
另外不要给不必要的人权限,会是个安全隐患。
我为这个问题折腾了一个星期
进程
目录/文件