阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

如何在CentOS Linux 7.5上安装Nginx

147次阅读
没有评论

共计 2254 个字符,预计需要花费 6 分钟才能阅读完成。

Nginx 发音引擎 x 是一个免费的开源高性能 HTTP 和反向代理服务器,负责处理互联网上一些最大的网站的负载。本教程将教你如何在你的 CentOS Linux 7.5 机器上安装和管理 Nginx。

 

安装 Nginx

Nginx 包可在 EPEL 存储库中找到。

如果您没有安装 EPEL 存储库,可以运行以下命令:

sudo yum install epel-release

如何在 CentOS Linux 7.5 上安装 Nginx

我们现在可以通过执行以下命令来安装 nginx 包:

sudo yum install nginx

如果这是您第一次从 EPEL 存储库安装包装,yum 可能会提示您导入 EPEL GPG 密钥:

从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 检索密钥
导入 GPG key 0x352C64E5:
 用户 ID    : “Fedora EPEL (7) <epel@fedoraproject.org>”
 指纹      : 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 软件包    : epel-release-7-11.noarch (@extras)
 来自      : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
是否继续?[y/N]:y

如果是这种情况,请键入 y 并按 Enter 键。

安装完成后,启用并启动 Nginx 服务:

sudo systemctl enable nginx
sudo systemctl start nginx

如果您正在运行防火墙,则还需要打开端口 80 和 443:

sudo firewall-cmd –permanent –zone=public –add-service=http
sudo firewall-cmd –permanent –zone=public –add-service=https
sudo firewall-cmd –reload

如何在 CentOS Linux 7.5 上安装 Nginx

我们现在可以检查 Nginx 服务的状态和版本:

sudo systemctl status nginx

示例输出:

● nginx.service – The nginx HTTP and reverse proxy server
  Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
  Active: active (running) since 二 2018-05-15 10:09:59 CST; 57s ago
  Process: 7149 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 7147 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 7142 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 7151 (nginx)
  CGroup: /system.slice/nginx.service
          ├─7151 nginx: master process /usr/sbin/nginx
          └─7152 nginx: worker process

5 月 15 10:09:58 localhost.localdomain systemd[1]: Starting The nginx HTTP an…
5 月 15 10:09:59 localhost.localdomain nginx[7147]: nginx: the configuration …
5 月 15 10:09:59 localhost.localdomain nginx[7147]: nginx: configuration file…
5 月 15 10:09:59 localhost.localdomain systemd[1]: Failed to read PID from fi…
5 月 15 10:09:59 localhost.localdomain systemd[1]: Started The nginx HTTP and…
Hint: Some lines were ellipsized, use -l to show in full.

sudo nginx -v

nginx version: nginx/1.12.2

如何在 CentOS Linux 7.5 上安装 Nginx

最后,我们可以通过在您选择的浏览器中打开 http//YOUR_IP 来验证安装,并且您应该能够看到默认的 Nginx 欢迎页面,如下所示:

如何在 CentOS Linux 7.5 上安装 Nginx

使用 systemctl 管理 Nginx 服务

我们可以像任何其他系统单元一样管理 Nginx 服务。

要停止 Nginx 服务,请运行:

sudo systemctl stop nginx

要再次启动,请键入:

sudo systemctl start nginx

重新启动 Nginx 服务:

sudo systemctl restart nginx

在进行一些配置更改后重新加载 Nginx 服务:

sudo systemctl reload nginx

如果你想禁用 Nginx 服务在启动时启动:

sudo systemctl disable nginx

并重新启用它:

sudo systemctl enable nginx

如何在 CentOS Linux 7.5 上安装 Nginx

阅读推荐:

如果您想用免费的 LetsEncrypt SSL 证书保护您的网站,可以查看以下指南:

让我们在 CentOS 7 上使用 Let’s Encrypt 以保护 Nginx  https://www.linuxidc.com/Linux/2018-05/152400.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计2254字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中