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"
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.