Hidden domain name: the page you will jump to when accessing, but the address bar still displays
1. Configure the hidden domain name based on the root directory (that is, nginx reverse proxy)
Visit: 8002, jump to: 8001 page, the address bar url remains unchanged
server { listen 8002; server_name ; location / { proxy_pass :8001; # Reverse proxy to this url, the domain name must be able to resolve } }
2. Configure hidden domain names based on conditions
When accessing :8002/Gao Yuanyuan.jpg, jump to the :8001/Gao Yuanyuan.jpg page, the URL of the address bar remains unchanged. Note that there must also be Gao Yuanyuan.jpg below to access the data
server { listen 8002; server_name ; location ~.*\.(jpg|png)$ { proxy_pass :8001; #rewrite ^/pic/(.*) /(.*)/$1 break; #rewrite ^/(.*) .*/$1 break; } }
2.1. Condition-based hidden domain names
When accessing: 8002/js/Gao Yuanyuan.jpg, jump to: 8001/js/Gao Yuanyuan.jpg page
Note: The data must be accessed by /js/Gao Yuanyuan.jpg
server { listen 8002; server_name ; location /js/ { proxy_pass :8001; } }
2.2. Condition-based hidden domain names
When accessing: 8002/(any directory)/(any content), all jump to: 8001/js/(any content)
For example, visit: 8002/sfsfsfs/Gao Yuanyuan.jpg, jump to /org:8001/js/Gao Yuanyuan.jpg
server { listen 8002; server_name ; location / { proxy_pass :8001; rewrite ^/.*/(.*) /js/$1 break; # The premise is that there is this file: 8001/js/Gao Yuanyuan.jpg } }
3. Configure the hidden domain name based on conditions (reverse proxy + rewrite configuration)
When accessing :8002/Gao Yuanyuan.jpg, jump to the :8001/js/Gao Yuanyuan.jpg page, and the address bar remains unchanged
rewrite ^/(.) : means rewrite match: 8002/any content below, (.) means any content
/js/$1 break: means rewrite as :8001/js/(.), $1 corresponds to (.)
server { listen 8002; server_name ; location ~.*\.(jpg|png|gif)$ { # When matching request url ending with .jpg|png|gif proxy_pass :8001; # Reverse proxy to this address rewrite ^/(.*) /js/$1 break; # and rewrite the requested url body to /js/$1 } }
4. Condition-based hidden domain name 2 (reverse proxy + rewrite)
This experiment was completed under macbook m1 desktop Desktop
Note: /aws/ must exist in 2 websites
(1) When visiting/aws/hour,Jump to/ server { listen 80; server_name ; location /aws/ { rewrite /aws/(.*)$ /$1 break; # Match /aws/[Arbitrary] in the url and jump to [Arbitrary] in the root directory of the website $1=first (.*) } } (2) When visiting/aws/hour,Jump to/ server { listen 80; server_name ; location /aws/ { rewrite /aws/(.*)$ /$1 break; #break no longer matches the following rewrite rules proxy_pass ; #The effect of changing the order of these two is the same } }
This is the article about Nginx configuration location + rewrite implementing hidden domain name configuration. For more related content on Nginx hidden domain name configuration, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!