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 reverse proxy a virtual domain by Nginx. 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
127.0.0.1 example1.com |
Check if the virtual domains are working
Open CMD
terminal on Windows, and run the virtual domain test command. e.g. ping example1.com
Pinging example1.com [127.0.0.1] with 32 bytes of data: |
Configuring Nginx Reverse Proxy
Configuring Nginx reverse proxy in conf\nginx.conf
http { |
Starting Nginx
Starting Nginx
cd D:\nginx-1.18.0 |
Check if your Nginx server is up and running
Visit http://localhost to see the “welcome to nginx!” page
Visit
Visit the virtual domain (server name) URL http://example1.com/{your_app_request_path}
Warning: Ensure you are not using an HTTP proxy client such as v2rayN before accessing virtual domain URLs.
Stop Nginx
CMD of Windows
cd D:\nginx-1.18.0 |
Git bash
cd D:\nginx-1.18.0 |
Reload the configuration of Nginx
CMD of Windows
cd D:\nginx-1.18.0 |
Git bash
cd D:\nginx-1.18.0 |
Note
- Ensure that the ports 80, 433… where Nginx is listening are not occupied.
- Ensure 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 stop the Nginx. Unless the Nginx process is killed in the task manager-Windows details or the Windows system is restarted.
- Before running
start nginx
, you must check if an Nginx server is running. If an Nginx server is running, you must runnginx -s stop first
. Repeatedly runningstart nginx
will start multiple Nginx servers, and you can’t stop all Nginx servers. Unless the Nginx process is killed in the task manager-Windows details or the Windows system is restarted.