Nginx转发解析长域名多路径域名为一级域名
Nginx解析短域名,例如:访问 http://192.168.1.23 可直接跳转到 http://192.168.1.23/webroot/decision
server {
listen 90;
server_name localhost;
#匹配/ 转到/webroot/decision上;
#^(.*)$表示/后任意部分,除非和其他location匹配否则一律转向/webroot/decision,如果无需这样可以修改这里location或者rewrite的正则;
#permanent表示重定向并返回301;
location / {
rewrite ^(.*)$ /webroot/decision permanent;
}
location /webroot {
proxy_pass http://crm;
......
}
}
实际案例:
server{
listen 443 ssl;
server_name ***.***.cn;
ssl_certificate ssl/server.crt;
ssl_certificate_key ssl/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
rewrite ^(.*)$ /webroot/decision permanent;
}
location /webroot {
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://xxx.xxx.xxx.xxx:8080;
}
}
喜欢请赞赏一下啦^_^