How to: Redirect an URL in NGINX

How to: Redirect an URL in NGINX

One might need to redirect to another URL in a number of scenarios. I will cover two examples for scenarios I have come across and how I addresses those issues:

I. Redirect from a naked domain to the www subdomain:

server {
listen 80;
server_name test.com;
return 301 $scheme://www.test.com$request_uri;
}

II. Redirect an Exchange Server Autodiscover subfolder to another domain:

#Redirect Autodiscover Requests
location ~* ^/Autodiscover
{
#               proxy_pass              https://outlook.office365.com:443;
#               proxy_cache_bypass      1;
return 301 $scheme://outlook.office365.com$request_uri;
}

For this last example you can chose 1 of two approaches: The first one which is commented out does a proxy to your Exchange Server AutoDiscover service. The problem with this approach is that you need to have the correct SSL certificate for your domain installed or you will have a number of warnings thrown out at you. This approach is useful if you want to cache responses, etc. My recommended approach is the one that is not commented out which is a normal redirect as the one you saw in the first example. Doing a redirect like this will avoid having Outlook trying to hit your server every now and then to check for the AutoDiscover directives. This is useful if you are hosting your domain in a non-exchange server host (you lack the AutoDiscover folder there).

Enhanced by Zemanta

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.