How to Do URL masking in NGINX

how to do url masking in nginx

When you move your web pages or domains, you might need to mask your new URLs under the old ones, without using redirection. Sometimes, you might need to serve some of your pages from a different domain or IP altogether, without changing browser URL. In this case, you can use URL masking for your website. Let us take a look at how to do URL masking in NGINX.


How to Do URL Masking in NGINX


1. Open NGINX config file

Open NGINX config file in a text editor. You will typically find it at /etc/nginx/nginx.conf

$ sudo vim /etc/nginx/nginx.conf


2. URL Masking in NGINX

Let’s say you want to map to a specific IP such that when users enter the URL your website loads content from the specified IP without changing URL in browser’s address bar.

In that case, add the following lines to your NGINX config file

server {
 listen 80;
 location / {

In the above code, we use proxy_pass directive to direct the requests sent to to the specified IP


On the other hand, if you want to alias a single URL such as

http:// number)


http:// number)/


then add the following lines to your server config file. We use proxy_buffering directive to alias the URL as required

location /sub {
 rewrite ^/sub/(.*)/ /sub/s?id=$1 break;
 proxy_buffering off;


3. Reload NGINX web server

Reload NGINX server to apply changes.

$ sudo service nginx reload


About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!