回答
收藏
分享
举报
Ngnix代理一个H5页面,内容空白
提问于2022-01-09 14:46

浏览 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;

}

已修改于2023-03-15 02:14



写下您的回答
发表回答
全部回答(1)

按点赞数排序

按时间排序

H5需要在js中处理#后的字符,nginx不会处理该字符

赞同

0

回复举报

回答于2022-10-31 14:11



回复jiayouachunyu
回复
提问者
刘畅
这家伙很懒还未留下介绍~
0
文章
1
问答
0
粉丝
相关问答

用rewrite指令应该比较容易吧,把正则表达式规则写好,然后301或者302跳转,可以参考nginx.org上的文档。

点赞 0
浏览 3.6k

根据你提供的配置和错误信息,有几个问题可能导致你无法访问多级目录的资源。下面是可能的解决方案:


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;

}

```

点赞 0
浏览 8.4k
点赞 0
浏览 1.8k