1、官方下载nginx压缩包 http://nginx.org/en/download.html

image

2、安装nginx

2.1、将下载的压缩包上传至linux服务器
2.2、安装 nginx 的相关依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2.3、解压压缩包
tar -zxvf nginx-1.22.0.tar.gz

image-1654134150895

2.4、生成 Makefile 可编译文件
cd nginx-1.22.0
./configure --with-http_ssl_module
2.5、编译安装
make
make install

3、启动nginx

3.1、进入安装目录
cd nginx 安装目录(默认 /usr/local/nginx/sbin)
3.2、执行启动命令
./nginx
3.3、查看是否启动成功
ps -ef | grep nginx

image-1654135006663

查看防火墙状态
systemctl status firewalld.service
关闭防火墙
systemctl stop firewalld.service
重启
systemctl restart firewalld.service
启动
systemctl start firewalld.service
禁止开机启动
systemctl disable firewalld.service
设置开机启用
systemctl enable firewalld.service
查看是否开机启动
systemctl is-enabled firewalld.service
查看已启动的服务列表
systemctl list-unit-files|grep enabled
查看已经开放的端口
firewall-cmd --list-ports
开启端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效

4、设置反向代理

/usr/local/nginx/conf(默认安装路径)目录中的nginx.conf配置文件
将端口改为自己项目的端口
image-1654135722525

5、重启nginx

cd nginx 安装目录(默认 /usr/local/nginx/sbin)
./nginx -s reload

6、关闭nginx

方式一   ./nginx -s stop
方式二   ./nginx -s quit
这两个命令的区别在于nginx -s stop是快速停止Nginx,而nginx -s quit是有序的停止Nginx,前者可能会导致数据没有完全保存;
方式三   taskkill /F /IM nginx.exe > nul
这种方法可以直接在cmd命令面板上使用,不必跑到Nginx的安装包下运行,当前两种方法无法奏效时可以尝试使用此方法,前两种方法适用于大部分版本的Nginx,但是个别版本的可能不使用,使用这个基本上就能解决了~

Q.E.D.