Open In App

Changing Nginx Port in Linux

Last Updated : 24 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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
How to Change Nginx Port in Linux

Open config file

Step 2: Then change the Listen line from 80 to 8082

How to Change Nginx Port in Linux

Change Nginx port

Now change the port number:

How to Change Nginx Port in Linux

Change the port to 8082

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
How to Change Nginx Port in Linux

Restart Nginx

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
How to Change Nginx Port in Linux

Check the port

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.

How to Change Nginx Port in Linux

Check port in browser


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads