Answer the question
In order to leave comments, you need to log in
How to fix 404 error after / in nginx-wsgi-flask bundle?
I can't understand what the error is:
Launched according to the instructions
When switching to "/" everything is fine, but when switching to "/hello" - nginx gives an error - 404
NGINX content
server {
listen 80;
listen [::]:80;
root /var/www/название домена/html;
index index.html index.nginx-debian.html;
server_name название домена;
location {
include proxy_params;
proxy_pass http://unix:/home/vasy/название домена/название домена.sock;
try_files $uri $uri/ =404;
}
}
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Index Page'
@app.route('/hello/')
def hello():
return 'Hello World'
if __name__ == "__main__":
app.run(host='0.0.0.0')
Answer the question
In order to leave comments, you need to log in
Remove this line from the Nginx config:
try_files $uri $uri/ =404;
The point is that Nginx must send all requests to the backend that it cannot answer itself. If the hello folder is really not in root, then Nginx will return 404.
SoreMix is also right. In Flask, the slash matters. You can turn off strict enforcement of slashes by adding code to your application:
app.url_map.strict_slashes = False
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question