linux 安装稳定版本nginx-1.20.2
目录
1、下载nginx
2、安装必要插件
[root@Tseng-HW ~]# yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
……
Upgraded:
cpp-8.4.1-1.el8.x86_64 gcc-8.4.1-1.el8.x86_64 krb5-libs-1.18.2-8.3.el8_4.x86_64 libgcc-8.4.1-1.el8.x86_64 libgomp-8.4.1-1.el8.x86_64 libselinux-2.9-5.el8.x86_64 libselinux-utils-2.9-5.el8.x86_64
libsepol-2.9-2.el8.x86_64 openssl-1:1.1.1g-15.el8_3.x86_64 openssl-libs-1:1.1.1g-15.el8_3.x86_64 python3-libselinux-2.9-5.el8.x86_64 zlib-1.2.11-17.el8.x86_64
Installed:
keyutils-libs-devel-1.5.10-6.el8.x86_64 krb5-devel-1.18.2-8.3.el8_4.x86_64 libcom_err-devel-1.45.6-1.el8.x86_64 libkadm5-1.18.2-8.3.el8_4.x86_64 libselinux-devel-2.9-5.el8.x86_64 libsepol-devel-2.9-2.el8.x86_64
libverto-devel-0.3.0-5.el8.x86_64 openssl-devel-1:1.1.1g-15.el8_3.x86_64 pcre-cpp-8.42-4.el8.x86_64 pcre-devel-8.42-4.el8.x86_64 pcre-utf16-8.42-4.el8.x86_64 pcre-utf32-8.42-4.el8.x86_64
pcre2-devel-10.32-2.el8.x86_64 pcre2-utf16-10.32-2.el8.x86_64 pcre2-utf32-10.32-2.el8.x86_64 zlib-devel-1.2.11-17.el8.x86_64
Complete!
[root@Tseng-HW ~]#
插件说明:
gcc 可以编译 C,C++,Ada,Object C和Java等语言
pcre pcre-devel pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库
zlib zlib-devel 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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)