How to Change Nginx Port in Windows


change nginx port number in windows

Bey default, Nginx serves port 80 (http requests). However, sometimes, you need to make it to listen to a non-standard port. In order to make Nginx listen to a non-standard port, you need to edit its configuration file, save it and restart your Nginx server to apply the changes. Let us take a look at how to change Nginx port in Windows.

 

How to Change Nginx Port in Windows

Here are the steps to change nginx port in windows.

First of all, open Nginx config file in a text editor. You will find the nginx config file (C:\nginx\conf\sites-enabled) in conf of your nginx installation.

 

Next, change the port number as shown. Here’s a sample config where Nginx listens to port 80


server {
  listen 80;
 server_name example.com;

 location / {
  root html;
  index index.html index.htm;
 }
}

 

Let’s say you want to make it listen to port 3200. Then update the server block as shown. Update localhost to your domain name


server {
  listen 3200;
 server_name example.com;

location / {
 root html;
 index index.html index.htm;
 }
}

 

Restart Nginx to apply changes


nginx -s stop
nginx -s reload

 

If you are changing port number for a remote server (not localhost), then make sure you have added a firewall exception for port 3200.

 

Open web browser and go to http://your_domain.com:3200 or http://yourserver_ip:3200

You will see the default Nginx page.

Nginx Default Page

 

 

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!