1、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
2、安装pcre
yum install pcre -y
pcre-config --version //查看版本
3、安装nginx
tar -xvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure //查看默认配置
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module //修改配置
--with-pcre=/usr/local/src/pcre-8.35 # 设置为自己安装的prce
make && make install
4、查看版本
/usr/local/nginx/sbin/nginx -v
5、启动
./nginx //以默认配置文件启动
./nginx -c /usr/local/nginx/conf/nginx.conf //指定配置文件启动
6、相关命令
/usr/local/nginx/sbin/nginx -t //查看配置文件是否正确
/usr/local/nginx/sbin/nginx -t -c conf/nginx.conf //nginx -t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
/usr/local/nginx/sbin/nginx -s reload # 重新载入配置文件
/usr/local/nginx/sbin/nginx -s reopen # 重启 Nginx
/usr/local/nginx/sbin/nginx -s stop # 停止 Nginx
7、加入系统管理
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload \
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod +x /usr/lib/systemd/system/nginx.service
systemctl status nginx
systemctl start nginx