CentOS下 安裝 Nginx

官方文檔https://nginx.org/en/linux_packages.html#RHEL-CentOShtml

 

安裝環境:Linux 服務器 CentOS 7.三、Root 權限linux

 

一、Install the prerequisites:nginx

sudo yum install yum-utils

 

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

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

命令:服務器

使用 vim 編輯 nginx.repo 文件工具

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

設置 Nginx 的 yum 源:ui

將如下內容粘貼進 nginx.repo 文件中url

[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 保存並退出spa

 

三、To install nginx, run the following command:

sudo yum install nginx

中途會輸入 y 確認安裝

 

四、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 確認

 

五、啓動 | 中止 | 重啓 Nginx:

# 啓動
systemctl start nginx.service

# 中止
systemctl stop nginx.service

# 重啓
systemctl restart nginx.service

 

六、查看 Nginx 全部安裝位置:

rpm 是 linux 的 rpm 包管理工具,-q 表明詢問模式,-l 表明返回列表

rpm -ql nginx

 

七、Nginx 配置文件:

/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
相關文章
相關標籤/搜索