You need to add APPLICATION_ROOT params to your flask app:
from flask import Flask, url_for
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
app = Flask(__name__)
app.config['APPLICATION_ROOT'] = '/cn'
if you need to host more than one application on your server, you can configure nginx to redirect all request to your specific flask app served by gunicorn like this. (it is not necessary if your server hosts only one application) Find out more about gunicorn and nginx here: https://docs.gunicorn.org/en/stable/deploy.html
server {
listen 8000;
server_name example.com;
proxy_intercept_errors on;
fastcgi_intercept_errors on;
location / {
include proxy_params;
proxy_pass http://unix:/path_to_example_flask_app_1/app.sock;
}
location /cn/{
include proxy_params;
proxy_pass http://unix:/path_to_example_flask_app_cn/app.sock;
}
}
serve flask app with gunicorn:
A complete exmaple here: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04
#move into project directory
/path_to_gunicorn/gunicorn --workers 3 --bind unix:app.sock -m 007 run:app
If you are using flask_restful instead, you can specify the root path also in the following way:
from flask import Flask
from flask_restful import Api
app = Flask(__name__)
app.debug = False
api = Api(app, prefix='/cn')
api.add_resource(ResourceClass, '/example_path') #will be served when the resource is requested at path /cn/example_path
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8000)