手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

如何在CentOS Linux 7.5上安装Nginx

[日期:2018-05-15] 来源:Linux公社  作者:醉落红尘 [字体: ]

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

本文永久更新链接地址https://www.linuxidc.com/Linux/2018-05/152399.htm

linux
相关资讯       安装Nginx  CentOS Linux 7.5 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款