Django,带有NGINX的uwsgi-uwsgi无法启动

时间:2019-05-22 22:12:56

标签: django nginx uwsgi django-2.2

我正在尝试配置测试网络服务器。

/home/webapp/uwsgi/sites/testproject.ini

[uwsgi]
plugins=python
home = /home/webapp/testproject/env
chdir = /home/webapp/testproject/testproject
pythonpath=/home/webapp/testproject
wsgi-file = /home/webapp/testproject/testproject/wsgi.py
http = 0.0.0.0:8000

socket = /var/run/testproject.sock
vacuum = true
chown-socket = nginx:nginx
chmod-socket = 666
uid = nginx
gid = nginx
listen.owner = nginx
listen.group = nginx

/etc/systemd/system/uwsgi.service

[Unit]
Description=uWSGI Emperor service
After=syslog.target

[Service]
ExecStart=/usr/local/bin/uwsgi --emperor /home/webapp/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

/ etc / nginx / sites-available / testproject

server {
   listen 0.0.0.0:8000 default_server;
   location / {
       include uwsgi_params;
       uwsgi_pass unix:/var/run/testproject.sock;
   }
}

并复制到已启用的网站

sudo ln -s /etc/nginx/sites-available/testproject /etc/nginx/sites-enabled

检查nginx配置

sudo nginx -t 

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

然后启动uwsgi和nginx sudo systemctl守护进程重新加载 sudo systemctl启动uwsgi sudo systemctl启动nginx

当我打开http://0.0.0.0:8000/时,出现错误502错误的网关

uwsgi看起来还不错

stemctl status uwsgi.service
● uwsgi.service - uWSGI Emperor service
   Loaded: loaded (/etc/systemd/system/uwsgi.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-05-23 22:40:20 CEST; 4min 47s ago
 Main PID: 27454 (uwsgi)
   Status: "The Emperor is governing 1 vassals"
    Tasks: 2 (limit: 4915)
   Memory: 2.6M
   CGroup: /system.slice/uwsgi.service
           └─27454 /usr/local/bin/uwsgi --emperor /home/webapp/uwsgi/sites

Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: !!! no internal routing support, rebuild with pcre support !!!
Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: chdir() to /home/webapp/testproject/testproject
Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: your processes number limit is 31045
Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: your memory page size is 4096 bytes
Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: detected max file descriptor number: 1024
Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: lock engine: pthread robust mutexes
Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: thunder lock: disabled (you can enable it with --thunder-lock)
Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: probably another instance of uWSGI is running on the same address (0.0.0.0:8000).
Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: bind(): Address already in use [core/socket.c line 769]
Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: Thu May 23 22:45:06 2019 - [emperor] curse the uwsgi instance testproject.ini (pid: 2786
Mai 23 22:51:12 Lenovo-B51-80 uwsgi[27454]: Thu May 23 22:51:12 2019 - [emperor] removed uwsgi instance testproject.ini

与nginx服务相同

systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-05-23 22:42:25 CEST; 4min 48s ago
     Docs: man:nginx(8)
  Process: 27626 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 27638 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 27639 (nginx)
    Tasks: 5 (limit: 4915)
   Memory: 5.3M
   CGroup: /system.slice/nginx.service
           ├─27639 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           ├─27640 nginx: worker process
           ├─27641 nginx: worker process
           ├─27642 nginx: worker process
           └─27643 nginx: worker process

Mai 23 22:42:25 Lenovo-B51-80 systemd[1]: Starting A high performance web server and a reverse proxy server...
Mai 23 22:42:25 Lenovo-B51-80 systemd[1]: Started A high performance web server and a reverse proxy server.

检查日志文件 /var/log/nginx/error.log

2019/05/23 22:42:47 [error] 28382#28382: *1 connect() to unix:/var/run/testproject.sock failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/var/run/testproject.sock:", host: "0.0.0.0:8000"

我该怎么做才能显示测试页?

ls -l /var/run/testproject.sock

srw-rw-rw- 1 root root 0 Mai 23 22:42 /var/run/testproject.sock

1 个答案:

答案 0 :(得分:0)

  

uwsgi看起来还不错

对我来说真的不太好-我明白了:

Mai 23 22:45:06 Lenovo-B51-80 uwsgi[27454]: bind(): Address already in use [core/socket.c line 769]

这似乎已将其他内容绑定到/var/run/testproject.sock。有可能吗?

  • 另一个进程正在运行并绑定到该套接字
  • 另一个进程正在运行并在端口8000上绑定

您不需要同时使用:

http = 0.0.0.0:8000

socket = /var/run/testproject.sock

想想像套接字这样的套接字,它会通过文件。 nginx根本不与端口8000通信,因为配置指向套接字。尝试在uwsgi配置中省略http参数,然后重新启动该服务。

编辑:我只是在阅读一些文档,而且套接字似乎也经历了类似http的参数。从他们的文档中:

http-to = /var/run/testproject.sock

我还看到一些对配置的引用,例如:

http-socket = /var/run/testproject.sock

无论哪种方式,似乎似乎已经有一个应用程序正在侦听端口8000和/var/run/testproject.sock,并且您必须以某种方式解决该问题。