SoFunction
Updated on 2025-04-06

How to set nginx startup port on Windows

1. Why set nginx startup port

By default, nginx will be started using port 80. However, in actual applications, port 80 may have been occupied by other programs, such as the IIS service that comes with the system. In order to avoid port conflicts and ensure that nginx can start and provide services normally, an unoccupied port is required.

2. Setting steps

Find nginx configuration file: Usually in the conf folder under the nginx installation directory, the file name is .

Edit configuration files: Open the file using a text editor (such as Notepad++).

Find the Port Settings section: Find the following code snippet in the file:

server {

       listen       80;

       server\_name  localhost;

in,listen 80;Indicates that nginx listens on port 80. Modify 80 to the port you want to set, such as 8080. The modified code is as follows:

server {

       listen       8080;

       server\_name  localhost;

Save configuration file: After the modification is completed, save the file.

Restart nginx service: Open the command prompt (CMD), enter the sbin folder of the nginx installation directory, and execute the commandnginx -s reload, the new port settings take effect.

3. Frequently Asked Questions and Solutions

Port occupied: If the set port has been occupied by other programs, nginx will not be able to start. You can use commandsnetstat -ano | findstr port numberTo view the process that occupies the port and end the corresponding process.

Configuration file error: When modifying the configuration file, if the syntax is incorrect, nginx cannot be started. You can use commandsnginx -tTo check whether the configuration file syntax is correct.

Through the above steps, you can successfully set the nginx startup port in your Windows system. Hope this article helps you who are currently configuring the server.

This is the article about how to set the nginx startup port in Windows. For more related content on setting the nginx startup port in Windows, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!