centos7.9离线安装nginx

本文详细描述了如何在CentOS系统中安装依赖包,从官网下载并配置Nginx,创建yum存储库,启动和停止服务,以及设置systemctl服务和环境变量,同时包括关闭防火墙的步骤。
摘要由CSDN通过智能技术生成

目录

1.安装依赖于源

2.网站下载软件包

3.创建路径

4.在/etc/yum.repos.d 下创建yum存储库:nginx.repo

5.启动nginx

6.关闭防火墙 

7、配置systemctl服务和环境变量


1.安装依赖包

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

2.网站下载软件包

根据需要在官网下载软件包

 https://nginx.org/en/download.html

3.创建路径

mkdir /usr/local/nginx

cd /usr/local/nginx

wget https://nginx.org/download/nginx-1.25.3.tar.gz

tar -zxvf  nginx-1.25.3.tar.gz

cd nginx-1.25.3

 ./configure  --prefix=/usr/local/nginx 

#不需要输,只是联网安装的参数,方便个人查询而已

--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-file-aio \
--with-http_realip_module

参数详细信息参照官网的文档:https://nginx.org/en/docs/configure.html 

make && make install

4.通过创建yum参考方式安装

vim /etc/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

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

官方文档:https://nginx.org/en/linux_packages.html#RHEL 

yum install -y yum-utils
yum install -y nginx  

#该方法需要联网,而且安装的版本未必是你要的版本,但该方法简单粗暴,不需要配置systemctl服务和环境变量

5.启动nginx

cd /usr/local/nginx/sbin

./nginx 

6.关闭防火墙 

直接关闭防火墙:

systemctl stop firewalld

或者开启相应端口

firewall-cmd --zone=public --add-port=80/tcp --permanent #放行80端口

firewall-cmd --reload #重载防火墙

 网页查看服务是否正常

表示服务正常 

./nginx  -s stop #关闭nginx 

7、配置systemctl服务和环境变量

#配置systemctl服务
vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.targe

systemctl daemon-reload #重载配置文件

 #配置环境变量
 echo ' export  PATH=$PATH:/usr/local/nginx/sbin ' >> /etc/profile
nginx -V #查看版本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

流痕457

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值