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
 
ASP站长网在进行一些配置更改后重新加载Nginx服务:
 
sudo systemctl reload nginx
 
如果你想禁用Nginx服务在启动时启动:
 
sudo systemctl disable nginx

dawei

【声明】:九江站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。