1、Nginx的安装版本区别常用版本分为四大阵营
- Nginx开源版 http://nginx.org/ Nginx
- plus 商业版 https://www.nginx.com
- openresty http://openresty.org/cn/
- Tengine http://tengine.taobao.org/
2、nginx-1.21.6.tar.gz解压源码目录

3、编译安装
#默认 --prefix指定nginx的安装目录 如果不带 默认安装到/usr/local/nginx目录下面./configure --prefix=/usr/local/nginx#检查所需要的库make#安装make install
4、 如果出现警告或报错
checking for OS+ Linux 3.10.0-693.el7.x86_64 x86_64checking for C compiler ... not found./configure: error: C compiler cc is not found#安装gccyum install -y gcc
./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre=<path> option.#安装perl库yum install -y pcre pcre-devel
./configure: error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib=<path> option.#安装zlib库yum install -y zlib zlib-devel
5、启动Nginx
进入安装好的目录 /usr/local/nginx/sbin
./nginx 启动./nginx -s stop 快速停止./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求./nginx -s reload 重新加载配置
6、 关于防火墙
关闭防火墙systemctl stop firewalld.service禁止防火墙开机启动systemctl disable firewalld.service放行端口firewall-cmd --zone=public --add-port=80/tcp --permanent重启防火墙firewall-cmd --reload
7、安装成系统服务 方便开机自启
创建服务脚本 : vi /usr/lib/systemd/system/nginx.service
服务脚本内容
[Unit]Description=nginx - web serverAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile=/opt/module/nginx/nginx-1.21.6/nginx/logs/nginx.pidExecStartPre=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -t -c /opt/module/nginx/nginx-1.21.6/nginx/conf/nginx.confExecStart=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -c /opt/module/nginx/nginx-1.21.6/nginx/conf/nginx.confExecReload=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -s reloadExecStop=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -s stopExecQuit=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -s quitPrivateTmp=true[Install]WantedBy=multi-user.target
重新加载系统服务systemctl daemon-reload启动服务systemctl start nginx.service开机启动systemctl enable nginx.service
8、卸载Nginx
1.首先输入命令 ps -ef | grep nginx检查一下nginx服务是否在运行。2.停止Nginx服务 /usr/sbin/nginx -s stop3.查找、删除Nginx相关文件 :whereis nginxfind查找相关文件find -name nginx依次删除find查找到的所有目录:rm -rf /usr/sbin/nginx再使用yum清理yum remove nginx
