uWSGI,Nginx,Flask应用服务不断失败

时间:2016-08-09 22:23:19

标签: nginx service deployment flask uwsgi

转到我的应用会产生502网关错误。发现这是因为我的how_lit.service失败了。但我很难找到原因。

尝试编辑应用程序和ini文档。无法弄清楚什么是错的。

Nginx和uWSGI服务正常运行。

服务状态:

    lit@digitalocean:~/howlit$ sudo service how_lit status
[sudo] password for lit: 
● how_lit.service - uWSGI instance to serve how lit rest api
   Loaded: loaded (/etc/systemd/system/how_lit.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2016-08-04 00:30:44 EDT; 5 days ago
  Process: 14294 ExecStart=/home/lit/howlit/env/bin/uwsgi --ini /home/lit/howlit/howlit.ini (code=exited, status=1/FAILURE)
 Main PID: 14294 (code=exited, status=1/FAILURE)

Aug 04 00:30:44 digitalocean systemd[1]: Started uWSGI instance to serve how lit rest api.
Aug 04 00:30:44 digitalocean uwsgi[14294]: [uWSGI] getting INI configuration from /home/lit/howlit/howlit.ini
Aug 04 00:30:44 digitalocean systemd[1]: how_lit.service: Main process exited, code=exited, status=1/FAILURE
Aug 04 00:30:44 digitalocean systemd[1]: how_lit.service: Unit entered failed state.
Aug 04 00:30:44 digitalocean systemd[1]: how_lit.service: Failed with result 'exit-code'.

目录和权限:

lit@digitalocean:~/howlit$ ls -l .
total 16
drwx---r-x 6 lit www-data 4096 Jul 29 11:47 env
-rwx---r-x 1 lit www-data  202 Aug  3 23:29 howlit.ini
-rwx---r-x 1 lit www-data 1203 Aug  3 23:01 how_lit_restapi.py
-rwxr-xr-x 1 lit www-data   72 Aug  3 23:27 wsgi.py

/etc/systemd/system/how_lit.service:

lit@digitalocean:~/howlit$ cat /etc/systemd/system/how_lit.service 
[Unit]
Description=uWSGI instance to serve how lit rest api
After=network.target


[Service]
User=lit
Group=www-data
WorkingDirectory=/home/lit/howlit/
Environment="PATH=/home/lit/howlit/env/bin"
ExecStart=/home/lit/howlit/env/bin/uwsgi --ini    /home/lit/howlit/howlit.ini

[Install]
WantedBy=multi-user.target

howlit.ini文件:

lit@digitalocean:~/howlit$ cat howlit.ini 
[uwsgi]
module = wsgi:app

uid = lit
gid = www-data



master = true
processes = 5


socket = how_lit_restapi.sock

chmod-sock = 666

vacum = true

die-on-term = true


gto = /var/log/uwsgi/%n.log

尝试手动操作:

lit@digitalocean:~/howlit$ /home/lit/howlit/env/bin/uwsgi --ini /home/lit/howlit/howlit.ini 
[uWSGI] getting INI configuration from /home/lit/howlit/howlit.ini
*** Starting uWSGI 2.0.13.1 (64bit) on [Tue Aug  9 18:28:25 2016] ***
compiled with version: 5.4.0 20160609 on 29 July 2016 11:48:08
os: Linux-4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016
nodename: digitalocean
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/lit/howlit
detected binary path: /home/lit/howlit/env/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 1896
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)
bind(): Permission denied [core/socket.c line 230]

权限错误再次出现?

解决方法:将我的套接字发送到tmp,但导航到我的网站时仍然出现错误的网关错误:(

1 个答案:

答案 0 :(得分:0)

解决了我自己的问题。

首先,我检查了我的服务。

sudo service nginx status
sudo service uwsgi status
sudo service how_lit status

然后我看到它们都在运行起来但仍然出现错误的网关错误。检查完日志后没有错误。我不得不承担我的配置。 然后我意识到我的错误......我从来没有重新启动所有这些,只是某些时候某些部分。所以我重新启动了每一个:

sudo service nginx restart
sudo service uwsgi restart
sudo service how_lit restart

现在可以了。

关于权限问题我尝试将套接字放入/ tmp目录,这样www-data组用户可以访问它以及root。我了解到你需要能够创建套接字并允许它访问系统。

我之后将它从tmp btw中移出来进行制作,因为我被告知这不是最佳做法。