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/;
}
}
这样改了就代理就不到后端去了,求教大佬们
1
kestrelBright OP 想要去掉 index.html
|
2
putyy 2022-08-23 13:53:09 +08:00
location /api/ {
proxy_http_version 1.1; proxy_set_header Connection "keep-alive"; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; if (!-f $request_filename) { proxy_pass http://127.0.0.1:8801; } } location / { index index.html index.htm; try_files $uri $uri/ /index.html; } 这是我惯用的配置,通常通过前缀标识 api, 其他的默认走前端 |
3
kestrelBright OP @putyy 本想不用前缀,搞了半天没办法
|