将Flask服务器连接到nginx子域后,当访问subdomain.mydomain.com/some_query时,我总是会收到404错误。但是当我访问subdomain.mydomain.com时,效果很好。
我已经将mydomain.com与静态Nginx服务器(带有try_files)一起使用
这是我的ini文件,conf文件
nginx conf(我的网域)
server {
listen 80;
listen [::]:80;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name mydomain.com www.mydomain.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
nginx conf(子域)
server {
listen 80;
listen [::]:80;
server_name subdomain.mydomain.com www.subdomain.mydomain.com;
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/[some name].sock;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
uwsgi ini
[uwsgi]
chdir = /[project pah]
module = app
uid = www-data
gid = www-data
virtualenv = /[project path]/venv
callable = app
chmod-socket = 666
socket = /tmp/[some name].sock
wsgi.py
from app import app
if __name__ == "__main__":
app.run()
app.py
from flask import Flask, render_template
app = Flask(__name__)
# This part works well
@app.route('/')
def hello_world():
return render_template('index.html')
# This part never works
@app.route('/asdf')
def hi():
return 'HIHI'
if __name__=='__main__':
app.run()