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

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

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

CentOS6.x 下 LNMP环境搭建(2、安装 Nginx)浏览器

CentOS6.x 下 LNMP环境搭建3、安装 PHPbash

2.1. 安装依赖包curl

# 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 模块tcp

2.2. 添加用户url

# useradd www -s /sbin/nologin -M

2.3. 安装.net

# 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表示成功rest

2.4. 启动code

# /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
相关文章
相关标签/搜索