Installation and use of nginx under windows and solving the problem that nginx cannot be started when port 80 is occupied

At present , nginx has been widely used. Today, we will first talk about the construction of nginx under Windows.

1. Installation

Go to the nginx official website to download the latest version for Windows, which is currently 1.11.10, as shown in the figure:

Download it and unzip it.

2. Run

Running nginx, the error is reported:

1
[emerg] 10348#10940: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

 

As shown in the figure:

You can also see it in the log log, open:

1
nginx-1.11.10\logs\error.log

 

As shown in the figure:

Nginx uses port 80 by default, but port 80 is occupied under Windows. Check it out:

Occupied by a process with pid 4, check:

It is a system process, look at the task manager:

really.

3. Problem solving

The solution is to make the system process no longer occupy port 80, and you need to modify the registry.

3.1 Open the registry

Type regedit in the launch bar

3.2 Find the registration item and modify it

turn up

1
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP

 

There is a Start registration item of type REG_DWORD:

The original value is 3:

Change to 0:

3.3 Restart the operating system

Restart the Windows system, the original system process will not occupy port 80.

4. Rerun nginx

Run in the nginx installation directory:

1
start nginx.exe

 

or:

1
nginx.exe

 

As shown in the figure:

In the task manager, you can see that there will be two processes started in the background:

5. Close nginx

1
nginx.exe -s stop

 

or:

1
nginx.exe -s quit

 

 

 

If it is not successful, you can check the error.log reason under the logs again. The following are other operation commands.

nginx -s stop quick exit
nginx -s quit graceful quit
nginx -s reload changing configuration, starting a new worker, quitting an old worker gracefully
nginx -s reopen reopening log files

6. Configuration test

We run nginx under cmd

The startup is successful. If there is an error, you can query the log (the log path is specified by the configuration file, you can modify it and save it to another location)

 

Close all Nginx processes: taskkill /im /f Nginx.exe. This command is very useful, the following two commands sometimes fail to shut down nginx.
Shut down the Nginx process: nginx -s stop / nginx -s quit

stop can quickly stop nginx, but may not save relevant information; while quit stops nginx in a complete and orderly manner, and this process will save relevant information.

Load the specified configuration file

 

C:\server\nginx-1.7.2>start nginx.exe -c conf/default.conf

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324670987&siteId=291194637