nginx gunicorn flask configuration
Now I map the /demo route to port 8088, how to rewrite the route
server {
listen 80;
server_name my_server;
location /demo {
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8088;
rewrite ^/demo/(.*)$ / last;
}
}
But if I write it like this, localhost/demo still doesn’t work, what should I do?
高洛峰2017-05-16 17:23:44
rewrite ^/demo/(.*)$ / last;
changed to
rewrite ^/demo/(.*)$ / break;
Data sources in last
会对server
块重新发起请求,break
则使用当前location
大家讲道理2017-05-16 17:23:44
If you say you want
If/demo is proxy to 8088, /demo/xx is proxy to 8088/xx
, you may need to do this:
server {
listen 80;
server_name my_server;
location / {
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8088;
rewrite ^/demo/(.*)$ / break;
}
}
But this can be processed directly in your background program, because the result is that accessing /demo/xx has the same effect as accessing /xx