How to configure Nginx during deployment

Knight
1 min readJan 24, 2021

Did you ever wanted to check whether your latest deployment is running fine or having some errors, before actually removing maintenance page? If you did and if you have Node.js or any other back end services served via Nginx proxy pass/load balancing this is the solution for your problem.

  • In testing device (chrome Browser in this example)
  1. Install extension Modify Header Value (HTTP Headers) (Assuming you would be verifying your application using chrome browser, if not similar extension would be available in other browsers as well as the mobile SDKs or WebViews would have similar functionality)
  2. In the options page of the above extension add “X-Maintenance-Test” header with value “TRUE”(case sensitive without quotes and make sure no spaces on either side) for the required base url.
  • In Nginx config file on your deployment server, update server block of the domain name as shown below and reload Nginx.
server {
listen 80;
server_name abc.xyz.com;
...
if ($http_x_maintenance_test != "TRUE") {
return 503;
}
....
}

Once the Nginx is reloaded, from your pre configured chrome browser, you will be able to test your latest deployment, while all your regular users sees maintenance page. Once the basic testing is done, you can comment out the “if condition” block and simply reload Nginx. Your verified production deployment is available to all users.

NOTE: The header name in the Nginx config is small case with dash replaced with underscore in case you want to change the header name used in this article.

--

--

Knight

An entrepreneur with a decade of experience in building MEAN stack SaaS platforms.