* 索引
| 1.Connection refused | Nginx服務沒有運行 |
|---|---|
| 2.unexpected "}" in /etc/nginx/nginx.conf | 配置文件內(nèi)容語法錯誤了 |
| 3.Linux或windows 使用域名 | hosts沒有解析域名 |
| 4.is not treminated by | 沒有以...結束 |
| 5.404 找不到 | 站點目錄可能沒有創(chuàng)建,或者nginx.conf配置文件站點目錄寫錯了 |
| 6.403 Forbidden 權限拒絕 | 權限拒絕(第一種) |
| 7.403 Forbidden 權限拒絕 | 首頁文件不存在(第二種) |
| 8.Cannot assign requested address | 無法分配指定請求的ip地址 |
| 9.304 Not Modified | (提示)用戶讀取瀏覽器緩存 |
| 10.Address already in use | 地址已被使用 |
| 11.Connection refused | 連接拒絕 |
| 12. conflicting server name | 服務器名稱沖突 |
| 13.500 internal Server Error | 內(nèi)部服務器錯誤 |
| 14.Error establishing a database connection | 建立數(shù)據(jù)庫連接失敗 |
| 15.Can't connect to local MySQL server through socket | 連接不到本地的數(shù)據(jù)庫 |
| 16.Unit is masked | nginx服務被刪除了 |
| 17.bind() to 10.0.0.4:80 failed (99: Cannot assign requested address) | 把這個10.0.0.4的ip綁定到這臺機器 失敗了 |
內(nèi)部服務器錯誤1.Nginx服務沒有運行
80端口沒有開
重啟nginx服務 systemctl restart nginx
[17:10 root@web01 /etc/nginx/conf.d]# curl www.oldboy.com
curl: (7) Failed connect to www.oldboy.com:80; Connection refused
[17:10 root@web01 /etc/nginx/conf.d]# systemctl restart nginx
[17:10 root@web01 /etc/nginx/conf.d]# curl www.oldboy.com
www.oldboy.com
2.查看詳細Nginx錯誤提示 檢查語法 nginx -t
一般寶花括號說明配置文件內(nèi)容語法錯誤了
"}"不成對
systemctl
[root@web-204 html]# systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
[root@web-204 html]# nginx -t
nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:49
nginx: configuration file /etc/nginx/nginx.conf test failed
3./etc/hosts文件域名沒有解析
[root@web01 /etc/nginx]# curl blog.oldboy.com
<a >Found</a>.
4.server_name這行沒有以分號結尾 ";"
treminated 結束
40 server {
41 listen 80;
42 server_name blog.oldboy.com \\沒有以 ; 結尾
43 location / {
44 root /usr/share/nginx/html/blog;
45 index index.html index.htm;
46 }
47 }
48
49 }
5.報錯—404 找不到
站點目錄可能沒有創(chuàng)建,或者nginx.conf配置文件站點目錄寫錯了
[root@web01 ~]# cat /usr/share/nginx/html/{www,blog}/index.html
www.oldboy.com
blog.oldboy.com
[root@web01 ~]# curl blog.oldboy.com
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
* * *
<center>nginx/1.16.0</center>
</body>
</html
6.報錯—403 權限拒絕(第一種)
Forbidden 權限拒絕
模擬錯誤:站點目錄權限修改為000 測試完后改回644:
[09:34 root@web01 ~]# ll /usr/share/nginx/html/www/
total 4
-rw-r--r-- 1 root root 15 Jun 5 09:00 index.html
[09:35 root@web01 ~]# chmod 600 index.html
[09:35 root@web01 ~]# ls -l index.html
-rw------- 1 root root 15 Jun 5 09:00 index.html
[09:35 root@web01 ~]# curl www.oldboy.com
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.16.0</center>
</body>
</html>
7.報錯—403 首頁文件不存在(第二種)
首頁文件不存在 默認是找首頁文件
模擬將站點目錄移動到別處:
[16:35 root@web01 ~]# mv /usr/share/nginx/html/www/index.html /tmp/
[16:35 root@web01 ~]# curl www.oldboy.com
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.16.0</center>
</body>
</html>
8. Cannot assign requested address 無法分配指定請求的ip地址
本地沒有10.0.0.9 的ip
10.0.0.9:80 (failedCannot assign)
[root@web01 /etc/nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] bind() to 10.0.0.9:80 failed (99: Cannot assign requested address)
nginx: configuration file /etc/nginx/nginx.conf test failed
解決方法1:添加1個ip地址:
[root@web01 ~]# ip addr add 10.0.0.9/24 dev eth0 label eth0:1 \\添加此ip
9. 304 Not Modified 用戶讀取瀏覽器緩存
/var/log/nginx/access.log日志中顯示304
10.Address already in use 地址已被使用
nginx已經(jīng)啟動了,在使用80端口
只是提示,不是報錯
Address already in use
nginx正在運行中
11.Connection refused 連接拒絕
[16:25 root@web01 ~]# curl www.oldboy.com
curl: (7) Failed connect to www.oldboy.com:80; Connection refused
[16:25 root@web01 ~]# systemctl restart nginx
[16:25 root@web01 ~]# curl www.oldboy.com
www.oldboy.com
12. conflicting server name 服務器名稱沖突
域名沖突: 有兩個或多個 虛擬主機的域名相同了
解決方法:可以將默認 default.conf壓縮
[root 12:27:22 @web01 conf.d]# vim 01-www.conf
server {
listen 80;
server_name www.oldboy.com; \\域名重復
#charset koi8-r;
access_log /var/log/nginx/access_www.log main;
location / {
root /usr/share/nginx/html/www;
index index.html index.htm;
}
}
[root 12:35:02 @web01 conf.d]# cat default.conf
server {
listen 80;
server_name www.oldboy.com; \\域名重復
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
[16:52 root@web01 /etc/nginx/conf.d]# gzip default.conf
[16:52 root@web01 /etc/nginx/conf.d]# ll
total 16
-rw-r--r-- 1 root root 219 Jun 5 12:56 01-www.conf
-rw-r--r-- 1 root root 240 Jun 5 12:55 02-blog.conf
-rw-r--r-- 1 root root 488 Apr 23 22:34 default.conf.gz \\壓縮
-rw-r--r-- 1 root root 123 Jun 5 12:41 status.conf
13.500 internal Server Error
內(nèi)部服務器錯誤
設置了權限認證auth_basic_user_file
密碼文件權限不對
改為600
[09:45 root@web01 /etc/nginx]# chmod 600 htpasswd
[09:46 root@web01 /etc/nginx]# ll htpasswd
-rw------- 1 nginx nginx 45 Jun 6 09:30 htpasswd
14.Error establishing a database connection
建立數(shù)據(jù)庫連接失敗
搭建好的wordpress博客進不去
修改權限blog站點目錄的屬主屬組為nginx
[root@web01 ~]# chown -R nginx.nginx /usr/share/nginx/html/blog/
[root@web01 ~]# ll -d /usr/share/nginx/html/blog/
drwxr-xr-x 5 nginx nginx 4096 Jun 6 21:03 /usr/share/nginx/html/blog/
15.Can't connect to local MySQL server through socket
連接不到本地的數(shù)據(jù)庫
數(shù)據(jù)庫服務沒有開啟
[root@web01 html]# systemctl restart mariadb.service
16.Unit is masked nginx服務被刪除了
從別的機器拷貝一份
usr/sbin/nginx下的內(nèi)容沒了

17.

修改內(nèi)核參數(shù):
[root@lb01 nginx]# tail -1 /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
[root@lb01 nginx]# sysctl -p #生效
net.ipv4.ip_nonlocal_bind = 1
[root@lb02 ~]# tail -1 /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
[root@lb02 ~]# sysctl -p #生效
net.ipv4.ip_nonlocal_bind = 1
再重啟就可以了
[root@lb01 nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb01 nginx]# systemctl restart nginx












