Nginx reverse proxy + URL rewrite
        Posted  
        
            by 
                jeffreyveon
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by jeffreyveon
        
        
        
        Published on 2012-04-15T17:31:28Z
        Indexed on 
            2012/04/15
            17:33 UTC
        
        
        Read the original article
        Hit count: 425
        
Nginx is running on port 80, and I'm using it to reverse proxy URLs with path /foo to port 3200 this way:
location /foo {
                proxy_pass http://localhost:3200;
                proxy_redirect     off;
                proxy_set_header   Host $host;
}
This works fine, but I have an application on port 3200, for which I don't want the initial /foo to be sent to. That is - when I access http://localhost/foo/bar, I want only /bar to be the path as received by the app. So I tried adding this line:
rewrite ^(.*)foo(.*)$ http://localhost:3200/$2 permanent;
This causes 302 redirect (change in URL), but I want 301. What should I do?
© Server Fault or respective owner