浏览 5.7k
同一个Nginx,配置了多个代理,其中一个原始站点是asp.net,正常。另一个是h5的,配置后没有提示错第一个是正常的。
第二个是个H5的网站不行,正常访问是:
https://TestH5/RegH5/#/pages/login/login
会自动跳到(#号没有了) https://TestH5/RegH5/pages/login/login
设置代理后访问:
https://bbb/RegH5/#/pages/login/login
不显示错误,浏览器显示了正确的标题,但内容是空白的。
节点配置如下:
location /aaa/ {
#这个是Asp.net的,正常使用。
proxy_pass https://test/myDemo/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_connect_timeout 4s; #配置点1
proxy_read_timeout 60s; #配置点2,
proxy_send_timeout 12s; #配置点3
proxy_buffer_size 1M;
proxy_buffers 8 1M;
proxy_busy_buffers_size 1M;
proxy_temp_file_write_size 1M;
}
location /bbb/ {
#这个是H5的,不行。
proxy_pass https://TestH5/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_connect_timeout 4s; #配置点1
proxy_read_timeout 60s; #配置点2,
proxy_send_timeout 12s; #配置点3
proxy_buffer_size 1M;
proxy_buffers 8 1M;
proxy_busy_buffers_size 1M;
proxy_temp_file_write_size 1M;
}

按点赞数排序
按时间排序
根据你提供的配置和错误信息,有几个问题可能导致你无法访问多级目录的资源。下面是可能的解决方案:
1. 尝试一:访问/applet/img/user/fitness_logo2.png 提示404的配置:
```
location / {
root /app/docker/statics/web;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /applet {
root /app/docker/statics;
index index.html;
}
```
这个配置中,`location /applet` 指定了根目录为 `/app/docker/statics`,而你的资源实际路径是 `/app/docker/statics/applet`。因此,你需要在 `location /applet` 的配置中添加 `/applet` 部分,以便正确地指向资源路径。修改后的配置如下:
```
location / {
root /app/docker/statics/web;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /applet {
root /app/docker/statics;
index index.html;
try_files $uri $uri/ /applet$uri /applet$uri/ =404;
}
```
2. 尝试二:访问/applet/img/user/fitness_logo2.png 提示404的配置:
```
location / {
root /app/docker/statics/web;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /applet {
alias /app/docker/statics/applet;
}
```
在这个配置中,你使用了 `alias` 指令来映射 `/applet` 到 `/app/docker/statics/applet` 目录。但是,由于你的请求是 `/applet/img/user/fitness_logo2.png`,Nginx 尝试将请求 `/applet/img/user/fitness_logo2.png/` 解析为目录,并在该目录下寻找索引文件,导致出现错误。为了解决这个问题,你可以尝试在 `location /applet` 的配置中使用 `try_files` 指令来显式指定文件的匹配。修改后的配置如下:
```
location / {
root /app/docker/statics/web;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /applet {
alias /app/docker/statics/applet;
try_files $uri $uri/ =404;
}
```
微信公众号
加入微信群