Contents
  1. 1. Downloading Nginx for Windows
  2. 2. Configuring hosts file of Windows
  3. 3. Configuring Nginx Reverse Proxy
  4. 4. Starting Nginx
    1. 4.1. Starting Nginx
    2. 4.2. Stop Nginx
    3. 4.3. Reload configuration of Nginx

Sometimes we need to access our web projects running on local environments by domain names. We can use Nginx reverse proxy virtual domain, then we can use configured domain names to visit our local projects.

Downloading Nginx for Windows

Downloading Nginx for Windows from Nginx.

Configuring hosts file of Windows

Configuring virtual domains in C:\Windows\System32\drivers\etc\hosts

1
2
127.0.0.1 example1.com
127.0.0.1 example2.com

Configuring Nginx Reverse Proxy

Configuring Nginx reverse proxy in conf\nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
http {
...
server {
listen 80;
server_name example1.com;
location / {
proxy_pass http://127.0.0.1:8081;
}
}

server {
listen 80;
server_name example2.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}

}

Starting Nginx

Starting Nginx

1
2
cd D:\nginx-1.18.0
start nginx.exe

Stop Nginx

CMD of Windows

1
2
3
4
5
6
7
cd D:\nginx-1.18.0

# fast shutdown
nginx -s stop

# graceful shutdown
nginx -s quit

Git bash

1
2
3
4
5
6
7
cd D:\nginx-1.18.0

# fast shutdown
./nginx.exe -s stop

# graceful shutdown
./nginx.exe -s quit

Reload configuration of Nginx

CMD of Windows

1
2
cd D:\nginx-1.18.0
nginx -s reload

Git bash

1
2
cd D:\nginx-1.18.0
./nginx.exe -s reload

Note

  1. Ports 80, 433… of Nginx listened can’t be occupied.
  2. You must use Nginx commands to start and stop Nginx, else you can’t to stop the Nginx. Unless to kill Nginx processes on Task Manager - Details of Windows, or to restart the Windows system.
  3. Before run start nginx, you need to check is there an Nginx server is running. If there is an Nginx server is running, you must run nginx -s stop firstly. Repeatedly running start nginx, it will start multiple Nginx server and you can’t stop all Nginx servers. Unless to kill Nginx processes on Task Manager - Details of Windows, or to restart the Windows system.
Contents
  1. 1. Downloading Nginx for Windows
  2. 2. Configuring hosts file of Windows
  3. 3. Configuring Nginx Reverse Proxy
  4. 4. Starting Nginx
    1. 4.1. Starting Nginx
    2. 4.2. Stop Nginx
    3. 4.3. Reload configuration of Nginx