当前位置: 首页 > 新闻动态 > 技术教程

CentOS下安装Nginx实例分析

作者:PHPz 浏览: 发布日期:2023-05-11
[导读]:安装环境:linux服务器centos7.3、root权限1、installtheprerequisites:sudoyuminstallyum-utils2、tosetuptheyumrepository,createthefilenamed/etc/yum.repos.d/nginx.repowiththefollowingcontents:(注意替换os版本:$releasever,如centos版本是7,就替换成7)命令:使用vim编辑nginx.repo文件vim/etc/yum.re

安装环境: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
免责声明:转载请注明出处:http://m.jing-feng.com.cn/news/256045.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!