nginx三种安装方式
- 1.源码安装 (1.版本随意 2.安装复杂 3.升级繁琐 4.规范 5. 便于管理)
- 2.yum安装 (1.版本较低 2.安装简单 3.配置不易读)
- 3.官方仓库安装 (1.版本较新 2.安装简单 3.配置易读)
源码安装


cd /root/
wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar xf nginx-1.20.2.tar.gz
cd /root/nginx-1.20.2/
./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
./configure: error: C compiler cc is not
found
yum install -y gcc gcc-c++ glibc
./configure: error: the HTTP rewritemodule requires the PCRE library.You can either disable the module byusing --without-http_rewrite_moduleoption, or install the PCRE library intothe system, or build the PCRE librarystatically from the source with nginx byusing --with-pcre=<path> option.
yum install -y pcre-devel
/configure: error: SSL modules requirethe OpenSSL library.You can either do not enable themodules, or install the OpenSSL libraryinto the system, or build the OpenSSLlibrary statically from the sourcewith nginx by using --with-openssl=<path> option.
yum install -y openssl-devel
yum install -y openssl-devel pcre-devel gcc gcc-c++ glibc
make
make install
ln -s /opt/nginx-1.20.2/ /opt/nginx
vim /etc/profile.d/nginx.sh
export PATH="$PATH:/opt/nginx/sbin"
source /etc/profile
[root@web01 ~]
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/nginx/sbin
systemctl stop firewalld
vim /etc/sysconfig/selinux
selinux=disable
[root@web01 ~]
- 杀进程
- nginx -s stop
官方源安装




vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
yum install -y nginx
1.Nginx启动
[root@zls ~]
[root@zls ~]
2.Nginx停止
[root@zls ~]
[root@zls ~]
3.Nginx重启
[root@zls ~]
4.Nginx重载
[root@zls ~]
[root@zls ~]
yum安装nginx
yum instll -y nginx
[root@web01 ~]
-rw-r--r--. 1 root root 2523 Apr 11 17:05 CentOS-Base.repo
-rw-r--r--. 1 root root 664 Apr 11 17:05 epel.repo
换国内源
阿里源

gzip /etc/yum.repos.d/*
curl -o https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.4b001b11zvIY21
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY