![Uwsgi 从 root 启动,但不作为服务启动](https://linux22.com/image/805131/Uwsgi%20%E4%BB%8E%20root%20%E5%90%AF%E5%8A%A8%EF%BC%8C%E4%BD%86%E4%B8%8D%E4%BD%9C%E4%B8%BA%E6%9C%8D%E5%8A%A1%E5%90%AF%E5%8A%A8.png)
我已经为 flask 网站设置了 nginx + uwsgi。
这是我的 nginx
server {
listen 80;
server_name _;
location /static/ {
alias /var/www/site/app/static/;
}
location / {
uwsgi_pass 127.0.0.1:5080;
include uwsgi_params;
}
}
这是我的 uwsgi config.xml
<uwsgi>
<socket>127.0.0.1:5080</socket>
<autoload/>
<daemonize>/var/log/uwsgi_webapp.log</daemonize>
<pythonpath>/var/www/site/</pythonpath>
<module>run:app</module>
<plugins>python27</plugins>
<virtualenv>/var/www/venv/</virtualenv>
<processes>1</processes>
<enable-threads/>
<master />
<harakiri>60</harakiri>
<max-requests>2000</max-requests>
<limit-as>512</limit-as>
<reload-on-as>256</reload-on-as>
<reload-on-rss>192</reload-on-rss>
<no-orphans/>
<vacuum/>
</uwsgi>
当我尝试启动 uwsgi 服务(service uwsgi start
)时,它显示正常,但是没有 uwsgi 进程,并且我在日志中看到以下内容:
*** Starting uWSGI 1.0.3-debian (64bit) on [Fri Oct 25 00:43:13 2013] ***
compiled with version: 4.6.3 on 17 July 2012 02:26:54
current working directory: /
writing pidfile to /run/uwsgi/app/gsk/pid
detected binary path: /usr/bin/uwsgi-core
setgid() to 33
setuid() to 33
limiting address space of processes...
your process address space limit is 536870912 bytes (512 MB)
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
uwsgi socket 0 bound to TCP address 127.0.0.1:5080 fd 6
bind(): Permission denied [socket.c line 107]
但是当我以 root 身份启动 uwsgi 时
uwsgi --socket 127.0.0.1:5080 --module run --callab app --harakiri 15 --harakiri-verbose --logto2 tmp/uwsgi.log
它启动正常,重新启动 nginx 后我就可以访问网站了。
这可能是一个什么问题?
答案1
这真的很愚蠢。我花了几个小时试图弄清楚这一点,并在我发布这篇文章后立即找到了原因。有一个漏洞这让我尝试将 uid 和 gid 添加到配置中:
<uwsgi>
<socket>127.0.0.1:5080</socket>
<autoload/>
<daemonize>/var/log/uwsgi_webapp.log</daemonize>
<pythonpath>/var/www/site/</pythonpath>
<module>run:app</module>
<plugins>python27</plugins>
<virtualenv>/var/www/gsk/</virtualenv>
<processes>1</processes>
<uid>www-data</uid>
<gid>www-data</gid>
<enable-threads/>
<master />
<harakiri>60</harakiri>
<max-requests>2000</max-requests>
<limit-as>512</limit-as>
<reload-on-as>256</reload-on-as>
<reload-on-rss>192</reload-on-rss>
<no-orphans/>
<vacuum/>
</uwsgi>
添加这些之后,它启动了,重新启动 nginx 后它就可以正常工作了。