linux 安装稳定版本nginx-1.20.2
目录
1、下载nginx
2、安装必要插件
3、安装nginx
4、测试
5、启动nginx
6、访问测试(浏览器中输入ip地址)
7、将 nginx 添加到全局变量中(环境变量)
8、停止nginx
9、重启nginx
10、旧域名重定向到新域名
nginx
http://nginx.org/

zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装
openssl openssl-devel openssl是web安全通信的基石,没有openssl,可以说我们的信息都是在裸奔
3、安装nginx
- [root@Tseng-HW]# mkdir -p /usr/local/nginx
- [root@Tseng-HW]# cd /usr/local/nginx
- # 下载源代码
- [root@Tseng-HW nginx]# wget https://nginx.org/download/nginx-1.20.1.tar.gz
- # 解压
- [root@Tseng-HW nginx]# tar -zxvf nginx-1.20.2.tar.gz
- …………
- [root@Tseng-HW nginx]# cd nginx-1.20.2
- # 编译配置
- [root@Tseng-HW nginx-1.20.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module
- checking for OS
- + Linux 4.18.0-240.10.1.el8_3.x86_64 x86_64
- checking for C compiler ... found
- ………………
- # 编译
- [root@Tseng-HW nginx-1.20.2]# make
- make -f objs/Makefile
- make[1]: Entering directory '/usr/local/nginx/nginx-1.20.2'
- ………………
- # 安装
- [root@Tseng-HW nginx-1.20.2]# make install
- make -f objs/Makefile install
- make[1]: Entering directory '/usr/local/nginx/nginx-1.20.2'
- ………………
4、测试
- [root@Tseng-HW nginx-1.20.2]# cd
- [root@Tseng-HW ~]# cd /usr/local/nginx/sbin/
- # 查看版本
- [root@Tseng-HW sbin]# ./nginx -v
- nginx version: nginx/1.20.2
- # 测试nginx
- [root@Tseng-HW sbin]# ./nginx -t
- nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
- nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
- [root@Tseng-HW sbin]#
5、启动nginx
- [root@Tseng-HW sbin]# ./nginx
- [root@Tseng-HW sbin]#
6、访问测试(浏览器中输入ip地址)

7、将 nginx 添加到全局变量中(环境变量)
- [root@Tseng-HW ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
- [root@Tseng-HW ~]# nginx -t
- nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
- nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
- [root@Tseng-HW ~]#
8、停止nginx
从容停止服务器
nginx -s quit这种方法较stop相比就比较温和一些了,需要进程完成当前工作后再停止。
立即停止服务器
nginx -s stop这种方法比较强硬,无论进程是否在工作,都直接停止进程。
9、重启nginx
[root@Tseng-HW ~]# nginx -s reload
10、旧域名重定向到新域名
原文:https://blog.csdn.net/piaomiao_/article/details/121406066
server
{
listen 80;
server_name old.tseng.com;
rewrite ".*" https://new.tseng.com;
}