How to use Nginx reverse proxy virtual domain on Windows 10
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 | 127.0.0.1 example1.com |
check virtual domains are worked
Open cmd, run the virtual domain test command. e.g. ping example1.com
1 | Pinging example1.com [127.0.0.1] with 32 bytes of data: |
Configuring Nginx Reverse Proxy
Configuring Nginx reverse proxy in conf\nginx.conf
1 | http { |
Starting Nginx
Starting Nginx
1 | cd D:\nginx-1.18.0 |
Check Nginx is started
Visit http://localhost, see welcome to nginx! page
Visit
Visit the virtual domain (server name) URL http://example1.com
1 | server { |
Warning: Make sure you are not using an HTTP proxy client such as v2rayN before accessing virtual domain URLs.
Stop Nginx
CMD of Windows
1 | cd D:\nginx-1.18.0 |
Git bash
1 | cd D:\nginx-1.18.0 |
Reload configuration of Nginx
CMD of Windows
1 | cd D:\nginx-1.18.0 |
Git bash
1 | cd D:\nginx-1.18.0 |
Note
- Make sure that the ports 80, 433… where Nginx is listening are not occupied.
- Make sure you are not using an HTTP proxy client such as v2rayN before accessing virtual domain URLs.
- 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.
- 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 runnginx -s stop
firstly. Repeatedly runningstart 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.