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_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
#安装gcc
yum install -y gcc
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically 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_module
option, or install the zlib library into the system, or build the zlib library
statically 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 server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/opt/module/nginx/nginx-1.21.6/nginx/logs/nginx.pid
ExecStartPre=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -t -c /opt/module/nginx/nginx-1.21.6/nginx/conf/nginx.conf
ExecStart=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -c /opt/module/nginx/nginx-1.21.6/nginx/conf/nginx.conf
ExecReload=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -s reload
ExecStop=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -s stop
ExecQuit=/opt/module/nginx/nginx-1.21.6/nginx/sbin/nginx -s quit
PrivateTmp=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 stop
3.查找、删除Nginx相关文件 :whereis nginx
find查找相关文件
find -name nginx
依次删除find查找到的所有目录:rm -rf /usr/sbin/nginx
再使用yum清理
yum remove nginx