服务器上编译安装ngnix
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了服务器上编译安装ngnix相关的知识,希望对你有一定的参考价值。
操作系统: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
[[email protected] 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=<path> option.
[[email protected]]# yum -y install pcre-devel #解决上述问题:
[[email protected] nginx-1.10.1]#make && make install
[[email protected] nginx-1.10.1]#ln -s /application/nginx-1.10.1 /application/nginx
[[email protected] 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
[[email protected] 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)
[[email protected] 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
[[email protected] nginx-1.10.1]#ps -ef|grep nginx
root 6862 16136 0 09:17 pts/0 00:00:00 grep nginx
#通过以上操作检查,说明nginx并没有正常工作,分析原因是与apache引起端口冲突。
[[email protected]]# vi nginx.conf
listen 80; #改成 listen 9090
[[email protected]]# ./nginx -s reload #重启nginx后丢失nginx.pid,如何重新启动nginx
nginx: [error]invalid PID number "" in "/application/nginx-1.10.1/logs/nginx.pid"
[[email protected]]# ../sbin/nginx –c /application/nginx/conf/nginx.conf
[[email protected]]# ../sbin/nginx -s reload
[[email protected]]# netstat -lnt|grep 9090
tcp 0 0 0.0.0.0:9090 0.0.0.0:* LISTEN
[[email protected]]# 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
[[email protected]]# vi /etc/sysconfig/iptables
-A INPUT -p tcp-m state --state NEW -m tcp --dport 9090 -j ACCEPT #9090端口通过防火强
[[email protected]]# 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
本文出自 “sky9890” 博客,请务必保留此出处http://sky9896.blog.51cto.com/2330653/1793531
以上是关于服务器上编译安装ngnix的主要内容,如果未能解决你的问题,请参考以下文章
rust交叉编译配置:windows上编译linux可执行程序