CentOS6.x 下 LNMP环境搭建二、安装 Nginx

CentOS6.x 下 LNMP环境搭建(准备篇)

CentOS6.x 下LNMP环境搭建(一、安装 MySQL)

CentOS6.x 下LNMP环境搭建(二、安装 Nginx)

CentOS6.x 下LNMP环境搭建三、安装 PHP

2.1. 安装依赖包

# rpm -qa pcre* openssl* zlib*  <------- 检查所依赖的包是否已经安装
zlib-1.2.3-29.el6.x86_64
openssl-1.0.1e-48.el6_8.1.x86_64
pcre-7.8-7.el6.x86_64
# yum -y install pcre-devel openssl-devel zlib-devel

注:其中 pcre 用于 nginx 的 rewrite 模块

2.2. 添加用户

# useradd www -s /sbin/nologin -M

2.3. 安装

# cd /root/src
# tar -zxvf nginx-1.6.3.tar.gz && cd nginx-1.6.3
# ./configure \
--prefix=/lnmp/server/nginx-1.6.3 \
--error-log-path=/lnmp/log/nginx/error.log \
--http-log-path=/lnmp/log/nginx/access.log \
--user=www \
--group=www \
--with-http_realip_module \
--with-http_sub_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre
# make
# make install
# cd /lnmp/server
# ln -s /lnmp/server/nginx-1.6.3/ nginx
# ls -l

注:编译安装过程中可以使用命令【# echo $?】检查configure/make的执行结果,0表示成功

2.4. 启动

# /lnmp/server/nginx/sbin/nginx -t   <------- 检查配置文件语法
nginx: the configuration file /lnmp/server/nginx-1.6.3//conf/nginx.conf syntax is ok
nginx: configuration file /lnmp/server/nginx-1.6.3//conf/nginx.conf test is successful
# /lnmp/server/nginx/sbin/nginx  <------- 启动
检查:
# lsof -i :80
COMMAND  PID USER  FD  TYPE DEVICE SIZE/OFF NODE NAME
nginx  38366 root  6u IPv4 93417   0t0 TCP *:http (LISTEN)
nginx  38367 nginx  6u IPv4 93417   0t0 TCP *:http (LISTEN)
# netstat -tlunp|grep 80
tcp    0   0 0.0.0.0:80  0.0.0.0:*    LISTEN   38366/nginx
# wget 127.0.0.1
# curl 127.0.0.1

注:当浏览器无法访问时,尝试 SELinux、iptables

2.5. 添加启动脚本,之后可以通过 service nginx xxx 方式控制

# vim /etc/init.d/nginx   <------- 文件内容见附件 nginx.sh
# chmod 755 /etc/init.d/nginx
# service nginx
Usage: /etc/init.d/nginx {start|stop|reload|restart|configtest}
# service nginx configtest <------- 配置文件检查
nginx: the configuration file /lnmp/server/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /lnmp/server/nginx/conf/nginx.conf test is successful
# service nginx start <------- 启动
Starting Nginx:                      [ OK ]

2.6. 设置开机自启动

# chkconfig --add nginx
# chkconfig nginx on
# chkconfig --list|grep nginx
nginx     0:off  1:off  2:on  3:on  4:on  5:on  6:off

相关文章

文章浏览阅读903次。4.清除缓存目录(/var/cache/yum)下的软件...
文章浏览阅读1.5k次。Python 是一种高级解释性编程语言,已被...
文章浏览阅读2.6k次。打开终端或控制台,以root或具有sudo权...
文章浏览阅读744次,点赞24次,收藏26次。目标:通过AppSrv为...
文章浏览阅读1.1w次,点赞8次,收藏26次。chmod命令来自于英...
文章浏览阅读1.2k次。yum源的URL地址,本例中是文件系统的路...