【发布时间】:2018-06-17 18:58:33
【问题描述】:
我今天玩了 nginx Unit 应用程序服务器和 Python 3。只要我运行一个简单的 WSGI 应用程序,它就可以正常工作,但是在尝试使用 Flask 时我不会工作 (404)...
nginx 配置:
upstream unit_backend {
server 127.0.0.1:8300;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
server_name _;
location / {
}
location /unittest {
proxy_pass http://unit_backend;
proxy_set_header Host $host;
}
}
单元配置:
{
"listeners": {
"*:8300": {
"application": "test"
}
},
"applications": {
"test": {
"type": "python 3.5",
"processes": 4,
"user": "noisefloor",
"group": "noisefloor",
"path": "/home/noisefloor/code/unit_test",
"module": "wsgi"
}
},
"access_log": "/var/log/access.log"
}
wsgi.py 在浏览器中打开http://127.0.0.1/unittest 时起作用:
from datetime import datetime
def application(environ, start_response):
status = '200 OK'
headers = [('Content-type', 'text/plain; charset=utf-8')]
start_response(status, headers)
text = 'Hello World @ {}'.format(datetime.now())
return [text.encode('utf-8')]
当wsgi.py如下:
from flask import Flask
application = Flask(__name__)
@application.route('/')
def test():
return 'Hello Flask!'
它得到了 404,但我看到了调用 http://127.0.0.1:8300 时我期望看到的内容 - 所以它基本上可以工作,只是不明白为什么调用 http://127.0.0.1/unittest 时它不能工作
【问题讨论】: