Sometimes you’ll want Nginx to listen and communicate over not its default port, but a different port instead. when you want to do that, the steps below can be a good starting point. For example, if you want the Nginx HTTP server to sit behind a proxy server, then the proxy server must be configured to listen on the default port 80. In this case, Nginx must also be configured to listen on a different port than 80, since two services can’t be assigned one port to listen on. there would be contentions. This tutorial is going to show students and new users how to easily switch the Nginx default port from 80 to something else. like 8082. in this way, other services can use port 80 to communicate. When you’re ready to make this change, continue below:

Identifying Nginx Port Config File

To change the Nginx default port number, you need to look in a single directory, unlike Apache2. this is Nginx default virtual hosts directory /etc/nginx/sites-available. This directory is where you’ll find individual virtual host configuration files. Each of the files contains a port for Nginx to listen and communicate over. if you want to change the Nginx port, you’ll do it in each of the virtual host files. Below is the location to can change the Nginx default port numbers

Changing Nginx Port Number

Now that you’ve identified the files you can change the Nginx port number, continue below to begin making those changes. for this post, we’ll change the default port 80 to 8082 and port 443 to 444. First, run the commands below to open the port.conf file. Then change the Listen line from 80 to 8082

Restart Nginx

Now that you’ve changed the port number in all the files, run the commands below to restart Nginx. After that, the Nginx service will begin listening on the port you assigned above. That’s it! This is how one changes Nginx port numbers. You may also like the post below: