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.


Share this page:


Was this article useful? Have any suggestions or improvements to the information?

Also Read

Killing cPanel Backups via Command Line / Shell

From time to time you may find the cPanel backup system taking longer and affecting production...

Reset cPanel Max Defers for an Account

While viewing exim_mainlog and seeing the following: enforce_mail_permissions: Domain...

Clear cPanel Eximstats DB and Repairing the Eximstats DB

Over the time or due to spammers the eximstats database file may grow to a large size. To clear...

Failed to lock proc mutex: Permission denied

The error : Failed to lock proc mutex: Permission denied can occur when using mod_ruid2 with...

SpamAssassin Command Line Bayesian Learn Command cPanel

Once it is enabled, it is necessary to train spamassassin to learn what is junk mail and what is...