Nginx redirecting folder to another host or server

From time to time you may want to proxy out a path to another server or location. To perform a proxy with nginx including frontend only nginx use, edit the vhost file for the domain you would like to make the modification to and add the following above the location / {:


# /folder redirect to remote account
    location ^~ /folder/ {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwared-For $proxy_add_x_forwarded_for;
        proxy_intercept_errors on;
        proxy_pass http://remoteIP_or_hostname/;
}


Once saved restart nginx. Note, not all scripts will be happy about this configuration but we have found it to be the most friendly of the possible forwards.

  • 163 Users Found This Useful

Was this answer helpful?

Related Articles

htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

To solve “.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable” follow...

301 Redirect

This code will redirect all visitors who attempt to access the old-url.html page to the...

Redirecting non-www to www with htaccess

Redirecting non-www to www with .htaccessIf you ever point your www. record to another server...

What are these htaccess files that keep popping up?

Why .htaccess Files Keep Appearing in My Directories   If you notice .htaccess files...

How to create a temporary 302 redirect via htaccess

An easy way to create a temporary redirect from one page to another web page is to use the 302...



Save 30% on web hosting - Use coupon code Hosting30