客户反映:说了你的网站是nginx代理的,打开空 white。直接IP加地址访问是好的(http://ip:port)

故障排除:

1.打开chrome浏览器并访问它。拜访情况确实如客户描述的那样。

2.感觉打开了开发者工具chrome,发现有些请求网址是404,css,js。

3.找到客户希望服务器登录的帐户,并检查nginx配置文件。

upstream www.test.com{ server 127.0.0.1:8080;}server { listen 80; listen 443 ssl http2; ssl_certificate /usr/local/nginx/conf/ssl/www.test.com.pem; ssl_certificate_key /usr/local/nginx/conf/ssl/www.test.com.key; server_name www.test.com; access_log /data/wwwlogs/www.test.com_nginx.log combined; index index.html index.htm index.jsp; root /data/wwwroot/www.test.com; location ~ .*\\.(js|css)?$ { expires 7d; access_log off; }​ location / { proxy_pass http://www.test.com; include proxy.conf; }}

4.上面的配置有没有发现什么问题?起初,我没有注意到我认为配置文件是正确的。

我准备查一下nginx的日志,再次请求网址,再次检查nginx还是404。(我感觉很困惑),而且proxy _ pass http://www.test.com配置的很清楚。

失败原因:

因为“位置~。*\\.(js|css)”?$ \”的匹配被拦截,请求无法正常发送到下一个“location/”上,因此无法正常到达后端proxy_pass。

解决方法:

第一种解决方案是把后端静态文件(css和js)放到前端nginx machine/data/data/wwwroot/www . test . com中

第二种解决方案:修改配置文件。

upstream www.test.com{ server 127.0.0.1:8080;}server { listen 80; listen 443 ssl http2; ssl_certificate /usr/local/nginx/conf/ssl/www.test.com.pem; ssl_certificate_key /usr/local/nginx/conf/ssl/www.test.com.key; server_name www.test.com; access_log /data/wwwlogs/www.test.com_nginx.log combined; index index.html index.htm index.jsp; root /data/wwwroot/www.test.com; ​ location ~ .*\\.(js|css)?$ { proxy_pass http://www.test.com; expires 7d; access_log off; }​ location / { proxy_pass http://www.test.com; include proxy.conf; }}

发表评论

后才能评论