网站404或空白怎么办?

系统 Linux
客户反映:说自己的网站走nginx代理后,打开空白。直接IP加地址访问是好的(http://ip:port)。

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

[[275208]]

故障排查:

(1) 打开chrome浏览器,访问了下,访问情况真是客户描述的那样。

(2) 感觉打开chrome ,开发者工具,发现部分请求URL是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; 
  } 

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

(4) 大家有发现上面配置有问题不?刚开始我也没有注意,自认为配置文件是对 的。

打算检查nginx的日志,一遍请求URL,一遍查看nginx果然还是404.(感觉疑惑),明明配置了proxy_pass http://www.test.com。

故障原因:

是因为 “location ~ .*\.(js|css)?$” 这个匹配拦截掉了,请求不能正常发往下一个“location /” ,也就不能正常抵达后端proxy_pass了。

解决方法:

第一种解决方法:是将后端的静态文件(css 和js ),放入前置nginx 机器/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; 
  } 

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

 

责任编辑:赵宁宁 来源: Linux运维技术之路
相关推荐

2011-06-30 17:58:30

网站被K

2024-07-29 08:01:32

2011-03-29 16:30:18

2011-08-29 15:58:58

2015-12-07 14:11:01

2011-06-27 15:42:23

降权SEO

2021-09-28 10:55:12

钓鱼网站网络攻击信息安全

2009-11-03 08:56:02

linux死机操作系统

2017-02-21 13:11:43

SDN网络体系SDN架构

2024-04-22 08:17:23

MySQL误删数据

2022-12-19 11:31:57

缓存失效数据库

2022-05-19 08:01:49

PostgreSQL数据库

2018-01-28 20:39:39

戴尔

2019-10-12 09:50:46

Redis内存数据库

2022-07-05 11:48:47

MySQL死锁表锁

2015-10-22 09:09:59

BAT投资VC

2016-05-24 11:13:05

2017-12-21 20:01:38

润乾报表

2024-10-09 17:06:52

RedisHash哈希表

2011-07-28 13:45:06

点赞
收藏

51CTO技术栈公众号