nginx部署(centos系统)--访问失败404

一、说明
系统:centos 6.6
nginx版本:nginx-1.8.0
二、nginx安装
安装步骤
(1)安装依赖包:gcc,pcre,zlib,openssl
(2)安装nginx-1.8.0
1、安装依赖包:

cd /usr/local
yum install -y gcc gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

2、安装nginx-1.8.0

wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz 
cd nginx-1.8.0
./configure --user=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
make install
ls ../
cd ../nginx
cd sbin/
./nginx
ps -ef | grep nginx
root      1821     1  0 00:44 ?        00:00:00 nginx: master process ./nginx
nobody    1822  1821  0 00:44 ?        00:00:00 nginx: worker process
root      1824  1753  0 00:44 pts/0    00:00:00 grep nginx

在本机浏览器访问部署nginx的80端口http://...:80,显示图下页面即为部署成功。

至此nginx安装完毕。
3、修改配置文件
需要同时部署2个,

cd /usr/local/nginx/conf
cp nginx nginx.bak
vi nginx

启动异常,报错如下图,检查error.log报错
nginx启动异常

2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:1090 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:8380 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:1090 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:8380 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:1090 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:8380 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:1090 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:8380 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:1090 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: bind() to 0.0.0.0:8380 failed (98: Address already in use)
2018/07/12 17:37:18 [emerg] 5555#0: still could not bind()

检查网站的error.log

2018/07/12 01:37:28 [error] 2880#0: *45 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.23.254, server: www.***.cn, request: "GET /favicon.ico HTTP/1.1", upstream: "http://12.1.11.20:8080/*-**/html/*/index.***.ico", host: "192.168.23.22:8380", referrer: "http://192.168.23.22:8380/"
2018/07/12 01:37:28 [error] 2880#0: *45 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.23.254, server: www.***.cn, request: "GET / HTTP/1.1", upstream: "http://12.1.11.20:8080/***/html/**/index.html", host: "192.168.23.22:8380"

百度搜索错误
“(111: Connection refused) while connecting to upstream” 用户在连接时,若遇到后端upstream挂掉或者不通,会收到该错误

检查端口调用情况

netstat -ntlp

杀掉nginx进程发现,杀掉一次,还有一次,才彻底杀完。

[root@nginx22 nginx]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1493/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1365/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1597/master         
tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      5497/sshd           
tcp        0      0 0.0.0.0:8380                0.0.0.0:*                   LISTEN      1821/nginx          
tcp        0      0 0.0.0.0:1090                0.0.0.0:*                   LISTEN      1821/nginx          
tcp        0      0 0.0.0.0:49831               0.0.0.0:*                   LISTEN      1215/rpc.statd      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1195/rpcbind        
tcp        0      0 :::22                       :::*                        LISTEN      1493/sshd           
tcp        0      0 ::1:631                     :::*                        LISTEN      1365/cupsd          
tcp        0      0 ::1:25                      :::*                        LISTEN      1597/master         
tcp        0      0 ::1:6010                    :::*                        LISTEN      5497/sshd           
tcp        0      0 :::58432                    :::*                        LISTEN      1215/rpc.statd      
tcp        0      0 :::111                      :::*                        LISTEN      1195/rpcbind        
[root@nginx22 nginx]# kill -9 1821
[root@nginx22 nginx]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1493/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1365/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1597/master         
tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      5497/sshd           
tcp        0      0 0.0.0.0:8380                0.0.0.0:*                   LISTEN      5529/nginx          
tcp        0      0 0.0.0.0:1090                0.0.0.0:*                   LISTEN      5529/nginx          
tcp        0      0 0.0.0.0:49831               0.0.0.0:*                   LISTEN      1215/rpc.statd      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1195/rpcbind        
tcp        0      0 :::22                       :::*                        LISTEN      1493/sshd           
tcp        0      0 ::1:631                     :::*                        LISTEN      1365/cupsd          
tcp        0      0 ::1:25                      :::*                        LISTEN      1597/master         
tcp        0      0 ::1:6010                    :::*                        LISTEN      5497/sshd           
tcp        0      0 :::58432                    :::*                        LISTEN      1215/rpc.statd      
tcp        0      0 :::111                      :::*                        LISTEN      1195/rpcbind        
[root@nginx22 nginx]# kill -9 5529
[root@nginx22 nginx]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1493/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1365/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1597/master         
tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      5497/sshd           
tcp        0      0 0.0.0.0:49831               0.0.0.0:*                   LISTEN      1215/rpc.statd      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1195/rpcbind        
tcp        0      0 :::22                       :::*                        LISTEN      1493/sshd           
tcp        0      0 ::1:631                     :::*                        LISTEN      1365/cupsd          
tcp        0      0 ::1:25                      :::*                        LISTEN      1597/master         
tcp        0      0 ::1:6010                    :::*                        LISTEN      5497/sshd           
tcp        0      0 :::58432                    :::*                        LISTEN      1215/rpc.statd      
tcp        0      0 :::111                      :::*                        LISTEN      1195/rpcbind   

测试wget及curl返回值是否正常

[root@nginx22 logs]# netstat -lnt |grep 8180
tcp        0      0 0.0.0.0:8180                0.0.0.0:*                   LISTEN      
[root@nginx22 logs]# wget 127.0.0.1
--2018-07-12 23:14:43--  http://127.0.0.1/
正在连接 127.0.0.1:80... 失败:拒绝连接。
[root@nginx22 logs]# curl 127.0.0.1
curl: (7) couldn't connect to host

为什么?
还未解决,待解救。

猜你喜欢

转载自blog.csdn.net/come_back_fudeyun/article/details/81002799