安装
下载地址

1、安装编译工具及库文件

  1. yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

2、安装pcre

  1. yum install pcre -y
  2. pcre-config --version //查看版本

3、安装nginx

  1. tar -xvf nginx-1.6.2.tar.gz
  2. cd nginx-1.6.2
  3. ./configure //查看默认配置
  4. ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module //修改配置
  5. --with-pcre=/usr/local/src/pcre-8.35 # 设置为自己安装的prce
  6. make && make install

4、查看版本

/usr/local/nginx/sbin/nginx -v

5、启动

  1. ./nginx //以默认配置文件启动
  2. ./nginx -c /usr/local/nginx/conf/nginx.conf //指定配置文件启动

6、相关命令

  1. /usr/local/nginx/sbin/nginx -t //查看配置文件是否正确
  2. /usr/local/nginx/sbin/nginx -t -c conf/nginx.conf //nginx -t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
  3. /usr/local/nginx/sbin/nginx -s reload # 重新载入配置文件
  4. /usr/local/nginx/sbin/nginx -s reopen # 重启 Nginx
  5. /usr/local/nginx/sbin/nginx -s stop # 停止 Nginx

7、加入系统管理

vim /usr/lib/systemd/system/nginx.service

  1. [Unit]
  2. Description=nginx - high performance web server
  3. After=network.target remote-fs.target nss-lookup.target
  4. [Service]
  5. Type=forking
  6. PIDFile=/usr/local/nginx/logs/nginx.pid
  7. ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
  8. ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  9. ExecReload=/usr/local/nginx/sbin/nginx -s reload \
  10. ExecStop=/usr/local/nginx/sbin/nginx -s stop
  11. ExecQuit=/usr/local/nginx/sbin/nginx -s quit
  12. PrivateTmp=true
  13. [Install]
  14. WantedBy=multi-user.target

chmod +x /usr/lib/systemd/system/nginx.service
systemctl status nginx
systemctl start nginx