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

前端之家收集整理的这篇文章主要介绍了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

猜你在找的CentOS相关文章