利用nginx实现域名隐藏真实地址实现域名重定向
原创
©著作权归作者所有:来自51CTO博客作者jack_cap的原创作品,请联系作者获取转载授权,否则将追究法律责任
效果是当访问a.haowan.com/xxxxx时,请求的真实路径是 b.haowan.com/a/xxxxx server { listen 80; server_name a.haowan.com; index index.php index.html index.htm; root /data/www/a; location ~ ^/a/ { proxy_redirect off; proxy_set_header Host b.haowan.com; proxy_pass http://192.168.10.10:80; } location / { set $domain default; if ( $http_host ~* "^(.*)\.haowan\.com") { set $domain $1; } rewrite ^/(.*) /$domain/$1 last; } } server { listen 80; server_name b.haowan.com; index index.php index.html; root /data/www/b; location / { index index.html index.php; } } | |
|
原文链接:http://bbs.linuxtone.org/thread-9384-1-1.html