w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
nginx rewrite rule for redirection

Why do people use regexps for no reason and have all kind of problems with it?…

location /admin/ {
    proxy_pass http://host1:7000/;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;

This will automatically strip /admin/ from proxied request and prepend it in Location header (which is used in redirect).

See proxy_pass and proxy_redirect docs.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.