[程序员] 求教 nginx 同一域名配置多端

server { listen 80; server_name www.xxx.cc; set $base_path "/xxx/xxx"; root "${base_path}/vue/dist"; index index.html; location / { try_files $uri $uri/ /index.html$is_args$args; if (!-f $request_filename) { proxy_pass http://www.xxx1.cc; } } location /bb/ { alias "${base_path}/vue1/dist/"; index index.html index.htm; try_files $uri $uri/ /index.html$is_args$args; } location /bbapi/ { proxy_pass http://127.0.0.1:8095/; } }

现在必须是 www.xxx.cc/index.html 才能访问,try_files 没生效,想默认走前端,前端找不到就代理到后端。如果去掉 if ,try_files 有效,但后端访问不能有前缀。该怎么改?

还有如果加上 upstream

upstream xxx_server_name{ server http://www.xxx1.cc; } server { listen 80; server_name www.xxx.cc; set $base_path "/xxx/xxx"; root "${base_path}/vue/dist"; index index.html; location / { try_files $uri $uri/ /index.html$is_args$args; if (!-f $request_filename) { proxy_pass http:/xxx_server_name; } } location /bb/ { alias "${base_path}/vue1/dist/"; index index.html index.htm; try_files $uri $uri/ /index.html$is_args$args; } location /bbapi/ { proxy_pass http://127.0.0.1:8095/; } }

这样改了就代理就不到后端去了,求教大佬们

发表回复

您的电子邮箱地址不会被公开。