1、Nginx的安装版本区别常用版本分为四大阵营

3、编译安装

  1. #默认 --prefix指定nginx的安装目录 如果不带 默认安装到/usr/local/nginx目录下面
  2. ./configure --prefix=/usr/local/nginx
  3. #检查所需要的库
  4. make
  5. #安装
  6. make install

4、 如果出现警告或报错

  1. checking for OS
  2. + Linux 3.10.0-693.el7.x86_64 x86_64
  3. checking for C compiler ... not found
  4. ./configure: error: C compiler cc is not found
  5. #安装gcc
  6. yum install -y gcc
  1. ./configure: error: the HTTP rewrite module requires the PCRE library.
  2. You can either disable the module by using --without-http_rewrite_module
  3. option, or install the PCRE library into the system, or build the PCRE library
  4. statically from the source with nginx by using --with-pcre=<path> option.
  5. #安装perl库
  6. yum install -y pcre pcre-devel
  1. ./configure: error: the HTTP gzip module requires the zlib library.
  2. You can either disable the module by using --without-http_gzip_module
  3. option, or install the zlib library into the system, or build the zlib library
  4. statically from the source with nginx by using --with-zlib=<path> option.
  5. #安装zlib库
  6. yum install -y zlib zlib-devel

5、启动Nginx

进入安装好的目录 /usr/local/nginx/sbin

  1. ./nginx 启动
  2. ./nginx -s stop 快速停止
  3. ./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求
  4. ./nginx -s reload 重新加载配置

6、 关于防火墙

  1. 关闭防火墙
  2. systemctl stop firewalld.service
  3. 禁止防火墙开机启动
  4. systemctl disable firewalld.service
  5. 放行端口
  6. firewall-cmd --zone=public --add-port=80/tcp --permanent
  7. 重启防火墙
  8. firewall-cmd --reload

7、安装成系统服务 方便开机自启

创建服务脚本 : vi /usr/lib/systemd/system/nginx.service
服务脚本内容

  1. [Unit]
  2. Description=nginx - web server
  3. After=network.target remote-fs.target nss-lookup.target
  4. [Service]
  5. Type=forking
  6. PIDFile=/opt/module/nginx/nginx-1.21.6/nginx/logs/nginx.pid
  7. ExecStartPre=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -t -c /opt/module/nginx/nginx-1.21.6/nginx/conf/nginx.conf
  8. ExecStart=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -c /opt/module/nginx/nginx-1.21.6/nginx/conf/nginx.conf
  9. ExecReload=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -s reload
  10. ExecStop=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -s stop
  11. ExecQuit=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -s quit
  12. PrivateTmp=true
  13. [Install]
  14. WantedBy=multi-user.target
  1. 重新加载系统服务
  2. systemctl daemon-reload
  3. 启动服务
  4. systemctl start nginx.service
  5. 开机启动
  6. systemctl enable nginx.service

8、卸载Nginx

  1. 1.首先输入命令 ps -ef | grep nginx检查一下nginx服务是否在运行。
  2. 2.停止Nginx服务 /usr/sbin/nginx -s stop
  3. 3.查找、删除Nginx相关文件 whereis nginx
  4. find查找相关文件
  5. find -name nginx
  6. 依次删除find查找到的所有目录:rm -rf /usr/sbin/nginx
  7. 再使用yum清理
  8. yum remove nginx