Linux下安装nginx—使用官方源

本文介绍了如何在CentOS服务器上通过官方源安装Nginx,包括配置官方源、清除EPEL源影响、刷新yum缓存、安装Nginx、启动服务以及验证安装成功的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用官方源安装nginx

基于服务器:CentOS
1、配置官方源

vi /etc/yum.repos.d/nginx.repo

输入如下内容(参考https://nginx.org/en/linux_packages.html)

[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

2、清除epel源的影响(如果存在epel源则注释掉,没有请忽略)

mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak

3、yum重新生成缓存

yum clean all
yum makecache

4、yum安装nginx

yum install -y nginx

5、启动nginx

systemctl start nginx

6、查按nginx相关文件

[root@localhost ~]# rpm -qc nginx  #查询nginx配置文件
/etc/logrotate.d/nginx
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params

7、访问测试,输出”Welcome to nginx!“则说明部署OK

[root@localhost ~]# curl http://127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值