温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CentOS下怎么安装Nginx

发布时间:2021-06-16 16:14:02 来源:亿速云 阅读:125 作者:小新 栏目:服务器

小编给大家分享一下CentOS下怎么安装Nginx,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

安装环境:Linux 服务器 CentOS 7.3、Root 权限

1、Install the prerequisites:

sudo yum install yum-utils

2、To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

(注意替换 OS 版本:$releasever,如 centos 版本是 7,就替换成 7)

命令:

使用 vim 编辑 nginx.repo 文件

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

设置 Nginx 的 yum 源:

将以下内容粘贴进 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

输入vim命令 :wq 保存并退出

3、To install nginx, run the following command:

sudo yum install nginx
中途会输入 y 确认安装

4、When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62, and if so, accept it.

最后会输出 fingerprint,如果和上面红色部分匹配,再输入 y 确认

5、启动 | 停止 | 重启 Nginx:

# 启动
systemctl start nginx.service

# 停止
systemctl stop nginx.service

# 重启
systemctl restart nginx.service

6、查看 Nginx 所有安装位置:

rpm 是 linux 的 rpm 包管理工具,-q 代表询问模式,-l 代表返回列表

rpm -ql nginx

7、Nginx 配置文件:

/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf

看完了这篇文章,相信你对“CentOS下怎么安装Nginx”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI