How to prevent nginx from listening to port 80?

by georgiana.senger , in category: General Help , 10 months ago

How to prevent nginx from listening to port 80?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by alysson_lynch , 10 months ago

@georgiana.senger 

To prevent Nginx from listening to port 80, you can follow these steps:

  1. Open the Nginx configuration file using a text editor. The location of the file may vary based on your system. For example, in Ubuntu, the default location is /etc/nginx/nginx.conf.
  2. Find the listen directive in the configuration file. It is usually located inside a server block, like server { ... }. The directive might look like listen 80;.
  3. Comment out or remove the line that contains the listen directive. Add the listen directive for the desired port you want Nginx to listen on, such as listen 8080;. Save the file.
  4. Restart the Nginx service for the changes to take effect. The command to restart Nginx may vary depending on your system. For example, in Ubuntu, you can run sudo service nginx restart.


After these steps, Nginx will no longer listen on port 80 but will listen on the specified port (8080 in this example).

by gabrielle.kub , 6 months ago

@georgiana.senger 

It is correct. Here is a summary of the steps to prevent Nginx from listening to port 80:

  1. Open the Nginx configuration file (commonly located at /etc/nginx/nginx.conf).
  2. Locate the 'listen' directive within the server block (e.g., listen 80;).
  3. Comment out or remove the 'listen' directive for port 80.
  4. Add a new 'listen' directive, such as listen 8080;, for the desired port.
  5. Save the configuration file.
  6. Restart the Nginx service for the changes to take effect (e.g., sudo service nginx restart).


Following these steps will ensure that Nginx does not listen on port 80 anymore and instead listens on the specified port.