操作系统:CentOS release 6.8 (Final)

Web应用服务器软件:nginx-1.10.1.tar.gz

实战任务:编译安装nignx

下载:#wget http://nginx.org/download/nginx-1.10.1.tar.gz

#wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.20.tar.gz

# tar zxvf pcre2-10.20.tar.gz

#cd pcre2-10.20

#./configure

# make && make install

#useradd  nginx -s /sbin/nologin  -M

# wget  http://nginx.org/download/nginx-1.10.1.tar.gz

#tar  zxf nginx-1.10.1.tar.gz

#cd nginx-1.10.1

[root@sky9896 nginx-1.10.1]#./configure--user=nginx \

--group=nginx \

--prefix=/application/nginx-1.10.1\

--with-http_stub_status_module \

--with-http_ssl_module

./configure: error: theHTTP rewrite module requires the PCRE library.

You can either disable the module by using--without-http_rewrite_module

option, or install the PCRE library intothe system, or build the PCRE library

statically from the source with nginx byusing --with-pcre= option.

[[email protected]]# yum -y install pcre-devel #解决上述问题:

[root@sky9896 nginx-1.10.1]#make && make install

[root@sky9896 nginx-1.10.1]#ln -s /application/nginx-1.10.1 /application/nginx

[root@sky9896 nginx-1.10.1]#/application/nginx/sbin/nginx  -t

nginx: the configuration file/application/nginx-1.10.1/conf/nginx.confsyntax is ok

nginx: configuration file/application/nginx-1.10.1/conf/nginx.conftest is successful

[root@sky9896 nginx-1.10.1]#lsof -i :80

COMMAND  PID   USER   FD  TYPE  DEVICE SIZE/OFF NODE NAME

httpd   1732   root    4u IPv6   10810      0t0 TCP *:http (LISTEN)

sdsvrd  1899   root   15u IPv4 8828354      0t0  TCP bbs.jxatei.net:9965->110.86.5.94:http(ESTABLISHED)

httpd   5506 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5526 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5529 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5543 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5544 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5545 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5546 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5547 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5548 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5549 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd   5550 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd  17445 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd  30642 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd  30643 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd  30644 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd  30647 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd  30648 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd  30649 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd  30650 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

httpd  30651 apache    4u  IPv6  10810      0t0  TCP *:http (LISTEN)

[root@sky9896 nginx-1.10.1]#netstat -lnt|grep 80

tcp       0      0::ffff:127.0.0.1:8005       :::*                        LISTEN     

tcp       0      0 :::8009                     :::*                        LISTEN     

tcp       0      0 :::8080                     :::*                        LISTEN     

tcp       0      0 :::80                       :::*                        LISTEN    

 

[root@sky9896 nginx-1.10.1]#ps -ef|grep nginx

root     6862 16136  0 09:17 pts/0    00:00:00 grep nginx

#通过以上操作检查,说明nginx并没有正常工作,分析原因是与apache引起端口冲突。

[root@sky9896conf]# vi nginx.conf

  listen     80;  #改成 listen 9090

[root@sky9896sbin]# ./nginx -s reload  #重启nginx后丢失nginx.pid,如何重新启动nginx

nginx: [error]invalid PID number "" in "/application/nginx-1.10.1/logs/nginx.pid"

[root@sky9896conf]# ../sbin/nginx –c  /application/nginx/conf/nginx.conf

[root@sky9896conf]# ../sbin/nginx -s reload

[root@sky9896conf]# netstat -lnt|grep 9090

tcp        0     0 0.0.0.0:9090           0.0.0.0:*          LISTEN 

[root@sky9896conf]# ps -ef|grep nginx

root     10400 16136  0 09:24 pts/0    00:00:00 ./nginx

root     14560    1  0 09:32 ?        00:00:00 nginx: master process../sbin/nginx -c /application/nginx/conf/nginx.conf

nginx    14646 14560 0 09:33 ?        00:00:00 nginx:worker process                             

nginx    14647 14560 0 09:33 ?        00:00:00 nginx:worker process                             

nginx    14648 14560 0 09:33 ?        00:00:00 nginx: worker process                             

nginx    14649 14560 0 09:33 ?        00:00:00 nginx:worker process                             

nginx    14650 14560 0 09:33 ?        00:00:00 nginx:worker process                             

nginx    14651 14560 0 09:33 ?        00:00:00 nginx:worker process                             

nginx    14653 14560 0 09:33 ?        00:00:00 nginx: workerprocess                             

nginx    14654 14560 0 09:33 ?        00:00:00 nginx:worker process                             

root     15061 16136  0 09:34 pts/0    00:00:00 grep nginx

[root@sky9896conf]# vi  /etc/sysconfig/iptables

-A INPUT -p tcp-m state --state NEW -m tcp --dport 9090 -j  ACCEPT  #9090端口通过防火强

[root@sky9896conf]#  vi /etc/rc.local

/applicaction/nginx/sbin/nginx #在末尾加该语句,可以随系统启动服务

  小结,配置端口不冲突之后,每次重启服务还会导致nginx.pid丢掉,无法正常开启,估计主要原因是在一台服务器上配置了多个web服务,包括Apache、Tomcat和nginx,运行冲突导致。最终把下面两条语句放在/rc.local 文件中才解决nginx.pid的问题。

/applicaction/nginx/sbin/nginx

/application/nginx/sbin/nginx–c  /application/nginx/conf/nginx.conf