Web Nginx v1.14.2--重定向太多
在我使用Nginx的有限经验中,当我在一个域上部署多个WEB项目时,会得到太多的重定向 我想使用一个“位置”来匹配多个项目 文件路径:Web Nginx v1.14.2--重定向太多,web,nginx,Web,Nginx,在我使用Nginx的有限经验中,当我在一个域上部署多个WEB项目时,会得到太多的重定向 我想使用一个“位置”来匹配多个项目 文件路径:/mnt/vue/web和/mnt/vue/admin和/mnt/page/web 当我访问https://${domain}/page/single时,它是错误的。它重定向到https://${domain}/page/single/index.html/index.html/index.html/… 当我访问https://${domain}/vue/web时
/mnt/vue/web
和/mnt/vue/admin
和/mnt/page/web
当我访问https://${domain}/page/single时,它是错误的。它重定向到https://${domain}/page/single/index.html/index.html/index.html/…
当我访问https://${domain}/vue/web时,一切正常
我尝试过多种不同的方法,但似乎都不管用。有什么想法吗?提前谢谢
这是我的Nginx配置:
server {
listen 443 http2;
server_name ${domain};
ssl on;
ssl_certificate /etc/nginx/conf.d/cert/web/web.pem;
ssl_certificate_key /etc/nginx/conf.d/cert/web/web.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
# wechat verify
root /mnt/wechat;
# for vue h5-wechat
location ~ /(.*)/web {
root /mnt;
try_files $uri $uri/ /$1/web/index.html =404;
}
# for vue admin-web
location ~ /(.*)/admin {
root /mnt;
try_files $uri $uri/ /$1/admin/index.html =404;
}
# for api
location ~ /(.*)/api/(.*)$ {
proxy_pass http://172.16.184.254:$1;
rewrite /(.*)/api/(.*)$ /$2 break;
}
# for single pages !!!!! Where the problem occurred.
location ~ /(.*)/single/ {
alias /mnt/$1/web/;
index index.html;
}
# for cache
location ~ /(css|img|js|fonts|image)/ {
add_header Cache-Control "public, max-age=300";
}
location /files {
rewrite /files/(.*)$ /$1 break;
proxy_pass https://172.16.92.152;
}
}
server {
listen 80;
server_name ${domain};
return 301 https://$server_name$request_uri;
#rewrite ^(.*)$ https://$host$1 permanent;
}
在正则表达式
location
块中使用alias
,需要捕获整个URI。有关详细信息,请参阅
例如:
location ~ ^/(.*)/single/(.*)$ {
alias /mnt/$1/web/$2;
index index.html;
}
在正则表达式
location
块中使用alias
,需要捕获整个URI。有关详细信息,请参阅
例如:
location ~ ^/(.*)/single/(.*)$ {
alias /mnt/$1/web/$2;
index index.html;
}