Changing Nginx Port in Linux
Nginx, written by Igor Sysoev and released on October 4th, 2003, is a fast, open-source multi-functional web server. It also acts as a reverse proxy and loads balancer, apart from being a web server, allowing it to handle large numbers of concurrent HTTP connections and is mostly preferred to Apache in the hosting of high-traffic enterprise websites. It is used in high-traffic websites such as Netflix and Dropbox to deliver their content in a quick, reliable, and secure manner.
By default, the Nginx HTTP server listens for inbound connections and connects to port 80, which is the default web port. However, the TLS configuration, which is not supported in Nginx by default, listens to port 443 for secure connections.
You need to look at a single directory to adjust Nginx’s default port number, unlike Apache2 this is Nginx’s default virtual host directory /etc/nginx/sites-available. This is where you can find individual virtual host configuration files in this directory.
Let’s change the port with stepwise implementation:
Step 1: First, run the commands below to open the port.conf file
$ sudo nano /etc/nginx/sites-available/default
Step 2: Then change the Listen line from 80 to 8082
Now change the port number:
Step 3: Now that you’ve changed the port number in the config files, run the commands below to restart Nginx.
$ sudo systemctl restart nginx.service
Step 4: Check the table of local network sockets with the netstat or ss command. Port 8082 should be shown on the local network table of your computer.
$ netstat -tlpn| grep nginx OR $ ss -tlpn| grep nginx
Open a window and navigate to your server’s IP address or domain name on port 8082 to verify if the webserver can be accessed from the computers on your network. As seen in the screenshot below, you can see the default Nginx web page.
Please Login to comment...