# Nginx Reverse Proxy (Rewrite URL) - [Download Link](https://nginx.org/en/download.html) - [Basic Command](https://nginx.org/en/docs/windows.html) ![image](https://hackmd.io/_uploads/By68FuRIa.png) ![image](https://hackmd.io/_uploads/rJ0YKuR86.png) ## Window Domain Name Setting (DNS) File Path ``` C:\Windows\System32\drivers\etc\hosts ``` Inside hosts file add customUrl.com ```config 127.0.0.1 customUrl.com ``` ## Rewrite Url Setting - [Rewrite rule](https://www.nginx.com/blog/creating-nginx-rewrite-rules/) - [Setting](https://serverfault.com/a/379679) File Path ``nginx-V0.00 > conf > nginx.conf`` ```config http { # Rewrite Url setting put inside server # proxy_pass Link depend on IIS setting server { listen 80; server_name customUrl.com; # Add below if have multiple custom port need map to same url # http://127.0.0.1:5250 --> http://customUrl.com/path_A location /path_A { rewrite /path_A/(.*) /$1 break; proxy_pass http://127.0.0.1:5250; proxy_redirect off; proxy_set_header Host $host; } # http://127.0.0.1:5252 --> http://customUrl.com/path_B location /path_B { rewrite /path_B/(.*) /$1 break; proxy_pass http://127.0.0.1:5252; proxy_redirect off; proxy_set_header Host $host; } } } ``` ## Windows PowerShell ```powershell $ cd [to nginx.exe path] # Start Nginx $ start Nginx # Check Nginx is Alive $ tasklist /fi "imagename eq nginx.exe" # Stop/Close Nginx $ nginx.exe -s stop ``` ## Troubleshooting If get this error, please check if pc/server using port 80 \ For window, Check if iis using this Port, then turn it off and run nginx again Error log path ``nginx-V0.00 > logs > error.log`` ``` [emerg] 47188#70376: 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) ```