Friday, April 10, 2015

How to redirect of any url in Nginx to any another IP address of Apache2 server with same URL(proxy & reverse proxy pass)?

Redirect nginx url to apache2 ip address:

I have a website xyz.com on nginx server & any another website  xxx.xxx.xxx.xxx on apache2 server. Now i want to proxy pass xyz.com/hello to my ip address & also reverse proxy from my ip address. So, that my ip address will show on "xyz.com/hello"  this url.

For this:

Add in your nginx configuration:

location /hello {
                    proxy_pass http://xxx.xxx.xxx.xxx;
                  }


This will directly redirect  xyz.com/hello & xyz.com/hello/ to ip address xxx.xxx.xxx.xxx

Now come to apache2 configuration:

In case of wordpress set your .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


Also, set in wordpress admin panel's setting

WordPress Address (URL) :  http://xxx.xxx.xxx.xxx
Site Address (URL) : http://xyz.com/hello

Or  you can do it with any another way if you are not using wordpress or any another CMS.

Now your apache2 website xxx.xxx.xxx.xxx will be work on this url http://xyz.com/hello

Thanks.

No comments:

Post a Comment