用户反映访问不了我们的www.song.com这个网站,你如何排查?
用户方面:
能否上网
让用户访问其他的网站,看是否能访问
服务器方面:
1,服务器是否是开启状态
2,服务器的网络是否正常(ping命令)
3,检查nginx是否运行(ps aux|grep nginx)
4,检查端口号是否开放? --》查看防火墙
netstat
lsof
ss
5,看nginx的日志
access.log
error.log
6,查看服务器的防火墙是否关闭?
iptables -L
service firewalld status
top命令
top 是一个在 Linux 和其他类 Unix 系统上常用的实时系统监控工具。
[root@nginx ~]# top
top - 11:22:05 up 4 min, 3 users, load average: 1.20, 0.38, 0.15
Tasks: 134 total, 4 running, 130 sleeping, 0 stopped, 0 zombie
%Cpu(s): 84.8 us, 12.1 sy, 0.0 ni, 3.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1863252 total, 1049248 free, 372180 used, 441824 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1307932 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
11802 root 20 0 163796 34084 7856 R 87.5 1.8 0:00.20 cc1
11806 root 20 0 148192 14748 4188 R 43.8 0.8 0:00.07 cc1
1 root 20 0 191000 3856 2568 S 0.0 0.2 0:01.27 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.10 ksoftirqd/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
6 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u256:0
7 root rt 0 0 0 0 S 0.0 0.0 0:00.06 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 R 0.0 0.0 0:00.70 rcu_sched
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain
11 root rt 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
12 root rt 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/1
13 root rt 0 0 0 0 S 0.0 0.0 0:00.05 migration/1
14 root 20 0 0 0 0 S 0.0 0.0 0:00.13 ksoftirqd/1
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0
16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H
18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
19 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
20 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd
21 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
22 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd
23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
24 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
25 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
26 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd
27 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 md
28 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 edac-poller
29 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 watchdogd
30 root 20 0 0 0 0 S 0.0 0.0 0:00.60 kworker/0:1
31 root 20 0 0 0 0 S 0.0 0.0 0:00.08 kworker/1:1
36 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kswapd0
37 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd
38 root 39 19 0 0 0 S 0.0 0.0 0:00.33 khugepaged
and the system load averages for the past 1, 5, and 15 minutes.
System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.
系统平均负载是处于可运行状态或不可中断状态的平均进程数。处于可运行状态的进程正在使用CPU,或者正在等待使用CPU。处于不可中断状态的进程正在等待一些I/O访问,例如等待磁盘。取三个时间间隔的平均值。平均负载并不是按照系统中CPU的数量进行标准化的,因此平均负载为1意味着单个CPU系统一直处于加载状态,而在4个CPU的系统中则意味着75%的时间处于空闲状态。
MIME是什么?
MIME:媒体类型(通常称为 Multipurpose Internet Mail Extensions 或 MIME 类型)是一种标准,用来表示文档、文件或字节流的性质和格式。
浏览器通常使用 MIME 类型(而不是文件扩展名)来确定如何处理 URL,因此 Web 服务器在响应头中添加正确的 MIME 类型非常重要。如果配置不正确,浏览器可能会曲解文件内容,网站将无法正常工作,并且下载的文件也会被错误处理。
[root@nginx conf]# cat mime.types
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/avif avif;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
font/woff woff;
font/woff2 woff2;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/wasm wasm;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}
虚拟主机的配置-server
1,基于域名的虚拟主机 --》一个域名对应一个网站
server {
listen 80;
server_name www.feng.com;
location / {
root html/feng;
index index.html index.htm shouye.html;
}
error_page 404 /404.html;
}
server {
listen 80;
server_name www.peng.com;
location / {
root html/peng;
index index.html index.htm shouye.html;
}
}
2,基于ip的 --》一个网站对应一个公网ip
3,基于端口的虚拟主机 --》一个网站一个端口
优点: 节省服务器,省钱
缺点:一台虚拟服务器受到攻击,其他的会收到牵连,共用cpu、内存、磁盘、带宽,如果一台服务器的访问量特别大,会导致其他的网站访问的时候异常。
404错误页面使用
1、修改配置文件nginx.conf
server {
listen 80;
server_name www.feng.com;
location / {
root html/feng;
index index.html index.htm shouye.html;
}
error_page 404 /404.html;
#检测语法
[root@nginx conf]# nginx -t
nginx: the configuration file /usr/local/sclilin99/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/sclilin99/conf/nginx.conf test is successful
#重新加载配置文件
[root@nginx conf]# nginx -s reload
2、存放网站的网页目录下新建feng目录,里面新建index.html 和 404.html
[root@nginx feng]# pwd
/usr/local/sclilin99/html/feng
[root@nginx feng]# tree
.
├── 404.html
└── index.html
0 directories, 2 files
[root@nginx feng]# ls
404.html index.html
[root@nginx feng]# cat 404.html
<html>
<head>
<title>404 page not found</title>
</head>
<body>
<p>page not found</p>
<p><h1>admin: student Y </h1></p>
<p><img src=zuqiu.jpg width=500></p>
</body>
</html>
[root@nginx feng]# cat index.html
welcome to changsha city
3、添加域名解析
[root@nginx feng]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.221 www.feng.com
192.168.1.221 www.peng.com
4、测试访问
[root@nginx conf]# curl www.feng.com
welcome to changsha city
[root@nginx conf]# curl www.feng.com/studeng
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.4</center>
</body>
</html>
windows里测试访问(域名如果没有购买,需要在hosts文件里添加域名解析)
rewrite功能,页面跳转
[root@nginx feng]# cat 404.html
<html>
<head>
<title>404 page not found</title>
<meta http-equiv="refresh" content="5;url=http://www.baidu.com">
</head>
<body>
<p>page not found</p>
<p><h1>admin: student Y </h1></p>
<p><img src=zuqiu.jpg width=500></p>
</body>
</html>
5秒之后会跳转到百度页面
50x的状态码,代表是nginx的内部错误(限制请求数来实现)
#gzip on;
limit_req_zone $binary_remote_addr zone=perip:10m rate=1r/s;
server {
listen 80;
server_name www.feng.com;
location / {
root html/feng;
index index.html index.htm shouye.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
limit_req zone=perip burst=1 nodelay;
location = /50x.html {
root html;
}
}
[root@nginx conf]# nginx -s reload
访问
nginx的master和worker的关系
master管理worker进程,当worker进程死掉会重启一个,master是worker的父进程。
[root@nginx conf]# ps aux|grep nginx
root 7610 0.0 0.1 61596 2404 ? Ss 22:12 0:00 nginx: master process nginx
lilin 7620 0.0 0.1 61932 2480 ? S 22:14 0:00 nginx: worker process
lilin 7621 0.0 0.1 61932 2480 ? S 22:14 0:00 nginx: worker process
root 7623 0.0 0.0 112824 988 pts/0 S+ 22:14 0:00 grep --color=auto nginx
IO多路复用(默认是epoll)
解决高并发的问题
events {
worker_connections 2048;
use epoll;
}
[root@nginx conf]# nginx -s reload
[root@nginx conf]# ps aux|grep nginx
root 7610 0.0 0.1 61596 2404 ? Ss 22:12 0:00 nginx: master process nginx
lilin 7620 0.0 0.1 61932 2480 ? S 22:14 0:00 nginx: worker process
lilin 7621 0.0 0.1 61932 2480 ? S 22:14 0:00 nginx: worker process
root 7623 0.0 0.0 112824 988 pts/0 S+ 22:14 0:00 grep --color=auto nginx
[root@nginx conf]# lsof -p 7620
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 7620 lilin cwd DIR 253,0 333 17296052 /usr/local/sclilin99/conf
nginx 7620 lilin rtd DIR 253,0 265 64 /
nginx 7620 lilin txt REG 253,0 7915608 266518 /usr/local/sclilin99/sbin/nginx
nginx 7620 lilin DEL REG 0,4 60271 /dev/zero
nginx 7620 lilin mem REG 253,0 31344 30217 /usr/lib64/libnss_dns-2.17.so
nginx 7620 lilin mem REG 253,0 61560 30219 /usr/lib64/libnss_files-2.17.so
nginx 7620 lilin mem REG 253,0 155744 35553 /usr/lib64/libselinux.so.1
nginx 7620 lilin mem REG 253,0 109976 30229 /usr/lib64/libresolv-2.17.so
nginx 7620 lilin mem REG 253,0 15688 41972 /usr/lib64/libkeyutils.so.1.5
nginx 7620 lilin mem REG 253,0 67104 249558 /usr/lib64/libkrb5support.so.0.1
nginx 7620 lilin mem REG 253,0 210784 42160 /usr/lib64/libk5crypto.so.3.1
nginx 7620 lilin mem REG 253,0 15856 35555 /usr/lib64/libcom_err.so.2.1
nginx 7620 lilin mem REG 253,0 967776 249556 /usr/lib64/libkrb5.so.3.3
nginx 7620 lilin mem REG 253,0 320720 42155 /usr/lib64/libgssapi_krb5.so.2.2
nginx 7620 lilin mem REG 253,0 11448 35561 /usr/lib64/libfreebl3.so
nginx 7620 lilin mem REG 253,0 2156592 30201 /usr/lib64/libc-2.17.so
nginx 7620 lilin mem REG 253,0 197088 75252 /usr/lib64/libGeoIP.so.1.5.0
nginx 7620 lilin mem REG 253,0 90160 41942 /usr/lib64/libz.so.1.2.7
nginx 7620 lilin mem REG 253,0 2521224 42145 /usr/lib64/libcrypto.so.1.0.2k
nginx 7620 lilin mem REG 253,0 470328 249553 /usr/lib64/libssl.so.1.0.2k
nginx 7620 lilin mem REG 253,0 402384 41925 /usr/lib64/libpcre.so.1.2.0
nginx 7620 lilin mem REG 253,0 40600 30205 /usr/lib64/libcrypt-2.17.so
nginx 7620 lilin mem REG 253,0 142144 30227 /usr/lib64/libpthread-2.17.so
nginx 7620 lilin mem REG 253,0 19248 30207 /usr/lib64/libdl-2.17.so
nginx 7620 lilin mem REG 253,0 163312 29606 /usr/lib64/ld-2.17.so
nginx 7620 lilin DEL REG 0,4 60273 /dev/zero
nginx 7620 lilin 0u CHR 1,3 0t0 1058 /dev/null
nginx 7620 lilin 1u CHR 1,3 0t0 1058 /dev/null
nginx 7620 lilin 2w REG 253,0 27721 35731316 /usr/local/sclilin99/logs/error.log
nginx 7620 lilin 4u unix 0xffff927b77bf0000 0t0 60876 socket
nginx 7620 lilin 5u unix 0xffff927b367a8400 0t0 60875 socket
nginx 7620 lilin 6u IPv4 60272 0t0 TCP *:http (LISTEN)
nginx 7620 lilin 10w REG 253,0 44056 35731320 /usr/local/sclilin99/logs/access.log
nginx 7620 lilin 11w REG 253,0 27721 35731316 /usr/local/sclilin99/logs/error.log
nginx 7620 lilin 12u a_inode 0,10 0 7465 [eventpoll]
nginx 7620 lilin 13u a_inode 0,10 0 7465 [eventfd]
[root@nginx conf]# lsof -p 7620|grep poll
nginx 7620 lilin 12u a_inode 0,10 0 7465 [eventpoll]