flask - nginx rewrite routing
给我你的怀抱
给我你的怀抱 2017-05-16 17:21:44
0
3
808

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?

给我你的怀抱
给我你的怀抱

reply all(3)
伊谢尔伦

Visit my_server/demo and try?

小葫芦
rewrite ^/demo/(.*)$ / last;

changed to

rewrite ^/demo/(.*)$ / break;
Data sources in

last会对server块重新发起请求,break则使用当前location

大家讲道理

If you say you want

/demo is proxy to 8088, /demo/xx is proxy to 8088/xx

If

, 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template