nginx 的配置(开了 81 端口,方便调试):
[root@localhost ~]# cat /etc/nginx/conf.d/dev.auth.lan.conf
server
{
listen 81;
server_name dev.auth.lan;
root /var/web/dev.auth.lan;
location /
{
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}
}
uwsgi 的配置:
[root@localhost dev.auth.lan]# cat /etc/uwsgi.ini
[uwsgi]
uid = uwsgi
gid = uwsgi
pidfile = /run/uwsgi/uwsgi.pid
emperor = /etc/uwsgi.d
stats = /run/uwsgi/stats.sock
emperor-tyrant = true
cap = setgid,setuid
[root@localhost ~]# cat /etc/uwsgi.d/dev.auth.lan.ini
[uwsgi]
socket = :8000
chdir = /var/web/dev.auth.lan
wsgi-file = manager.py
master = true
process = 10
vacuum = true
daemonize = /var/log/dev.auth.lan.uwsgi.log
nginx 的运行情况(实心圆圈是绿灯):
[root@localhost ~]# systemctl status nginx -l
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since 六 2016-01-30 06:03:28 PST; 25min ago
Process: 936 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 861 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 848 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 991 (nginx)
CGroup: /system.slice/nginx.service
├─991 nginx: master process /usr/sbin/ngin
└─993 nginx: worker proces
1 月 30 06:03:28 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
1 月 30 06:03:28 localhost.localdomain nginx[861]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
1 月 30 06:03:28 localhost.localdomain nginx[861]: nginx: configuration file /etc/nginx/nginx.conf test is successful
1 月 30 06:03:28 localhost.localdomain systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
1 月 30 06:03:28 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.
uwsgi 的运行情况(也是绿灯):
[root@localhost ~]# systemctl status uwsgi -l
● uwsgi.service - uWSGI Emperor Service
Loaded: loaded (/usr/lib/systemd/system/uwsgi.service; enabled; vendor preset: disabled)
Active: active (running) since 六 2016-01-30 06:32:29 PST; 2s ago
Process: 2277 ExecStartPre=/bin/chown uwsgi:uwsgi /run/uwsgi (code=exited, status=0/SUCCESS)
Process: 2274 ExecStartPre=/bin/mkdir -p /run/uwsgi (code=exited, status=0/SUCCESS)
Main PID: 2281 (uwsgi)
Status: "The Emperor is governing 1 vassals"
CGroup: /system.slice/uwsgi.service
├─2281 /usr/sbin/uwsgi --ini /etc/uwsgi.ini
├─2283 /usr/sbin/uwsgi --ini /etc/uwsgi.ini
├─2284 /usr/sbin/uwsgi --ini dev.auth.lan.ini
└─2285 /usr/sbin/uwsgi --ini dev.auth.lan.ini
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: your server socket listen backlog is limited to 100 connections
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: your mercy for graceful operations on workers is 60 seconds
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: mapped 145536 bytes (142 KB) for 1 cores
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: *** Operational MODE: single process ***
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: *** no app loaded. going in full dynamic mode ***
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: *** uWSGI is running in multiple interpreter mode ***
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: spawned uWSGI master process (pid: 2284)
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: Sat Jan 30 06:32:29 2016 - [emperor] vassal dev.auth.lan.ini has been spawned
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: spawned uWSGI worker 1 (pid: 2285, cores: 1)
1 月 30 06:32:29 localhost.localdomain uwsgi[2281]: Sat Jan 30 06:32:29 2016 - [emperor] vassal dev.auth.lan.ini is ready to accept requests
端口也确实开了:
[root@localhost ~]# netstat -lpn | grep 8000
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 2284/uwsgi
项目目录下也确实有 manager.py
[root@localhost dev.auth.lan]# pwd
/var/web/dev.auth.lan
[root@localhost dev.auth.lan]# ls -alh
总用量 4.0K
drwxr-xr-x. 3 root root 39 1 月 30 06:36 .
drwxr-xr-x. 3 root root 26 1 月 30 02:32 ..
-rwxr-xr-x. 1 root root 132 1 月 30 06:10 manager.py
drwxr-xr-x. 5 root root 82 1 月 30 05:02 project
[root@localhost dev.auth.lan]# cat manager.py
#!/usr/bin/env python3
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "<span style='color:red'>I am app 1</span>"
[root@localhost dev.auth.lan]#
但是用浏览器访问那台服务器的 81 端口,就是报 502 , nginx 的日志(太长,加了换行进去):
2016/01/30 06:37:59 [crit] 993#0: *25 connect() to 127.0.0.1:8000 failed
(13: Permission denied)
while connecting to upstream, client: 192.168.124.1,
server: dev.auth.lan, request: "GET / HTTP/1.1",
upstream: "uwsgi://127.0.0.1:8000", host: "192.168.124.237:81"
@ethego
直接写 module = manager 依然不行,还是同样的报错,试了很多方法, uwsgi 的报错没了,但是依然是 502 。
[root@localhost dev.auth.lan]# cat /etc/uwsgi.d/dev.auth.lan.ini
[uwsgi]
socket = :8000
chdir = /var/web/dev.auth.lan
processes = 2
wsgi-file = /var/web/dev.auth.lan/manager.py
callable = app
plugins = python3
master = true
vacuum = true
[root@localhost dev.auth.lan]# systemctl status uwsgi
● uwsgi.service - uWSGI Emperor Service
Loaded: loaded (/usr/lib/systemd/system/uwsgi.service; enabled; vendor preset: disabled)
Active: active (running) since 六 2016-01-30 08:24:34 PST; 5s ago
Process: 4797 ExecStartPre=/bin/chown uwsgi:uwsgi /run/uwsgi (code=exited, status=0/SUCCESS)
Process: 4793 ExecStartPre=/bin/mkdir -p /run/uwsgi (code=exited, status=0/SUCCESS)
Main PID: 4801 (uwsgi)
Status: "The Emperor is governing 1 vassals"
CGroup: /system.slice/uwsgi.service
├─4801 /usr/sbin/uwsgi --ini /etc/uwsgi.ini
├─4803 /usr/sbin/uwsgi --ini /etc/uwsgi.ini
├─4804 /usr/sbin/uwsgi --ini dev.auth.lan.ini
├─4806 /usr/sbin/uwsgi --ini dev.auth.lan.ini
└─4807 /usr/sbin/uwsgi --ini dev.auth.lan.ini
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: your mercy for graceful operations on workers is 60 seconds
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: mapped 218304 bytes (213 KB) for 2 cores
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: *** Operational MODE: preforking ***
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x9b93c0 pid: 4804 (default app)
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: *** uWSGI is running in multiple interpreter mode ***
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: spawned uWSGI master process (pid: 4804)
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: Sat Jan 30 08:24:35 2016 - [emperor] vassal dev.auth.lan.ini has been spawned
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: spawned uWSGI worker 1 (pid: 4806, cores: 1)
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: spawned uWSGI worker 2 (pid: 4807, cores: 1)
1 月 30 08:24:35 localhost.localdomain uwsgi[4801]: Sat Jan 30 08:24:35 2016 - [emperor] vassal dev.auth.lan.ini is ready to accept requests
1
ethego 2016-01-30 22:45:13 +08:00 1
*** no app loaded. going in full dynamic mode ***
看到这玩意没有? |
2
ethego 2016-01-30 22:45:44 +08:00
wsgi 容器里没装东西
|
3
fyyz OP |
4
ethego 2016-01-30 22:59:28 +08:00
wsgi-file = manager.py 换成 module = manager 或者 module = manager:app
|
6
billlee 2016-01-31 00:33:33 +08:00 1
看到有 connect() to 127.0.0.1:8000 failed (13: Permission denied)
也许是 SELinux 的问题? |
9
Ansen 2016-01-31 10:57:30 +08:00 via iPhone
uwsgi 你用 http ,不要用 sockt
sockt 不是这样配置的( nginx ) |
10
jings 2016-01-31 13:21:46 +08:00
mark
|
11
aabbccli 2016-01-31 15:30:40 +08:00
用 SOCK 文件的话, NGINX 应该是这样
upstream first { server unix:///var/www/site/site.sock; } server { listen 80; server_name localhost; location / { include /etc/nginx/uwsgi_params; uwsgi_pass first; } } |