Nginx是一个免费的,开源的,高性能的HTTP和反向代理服务器,负责处理互联网上一些最大站点的负载。
本教程将教您如何在CentOS 7机器上安装和管理Nginx。
在CentOS上安装Nginx
按照以下步骤在CentOS服务器上安装Nginx:
01、EPEL存储库中提供了Nginx包。 如果您还没有安装EPEL存储库,可以输入以下命令:
yum install epel-release -y
02、键入以下yum命令安装Nginx:
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并按Enter键。
安装完成后,启用并启动Nginx服务:
#systemctl enable nginx #systemctl start nginx
使用以下命令检查Nginx服务的状态:
#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 六 2020-02-22 11:15:15 CST; 6s ago Process: 1625 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 1622 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 1621 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 1627 (nginx) CGroup: /system.slice/nginx.service ├─1627 nginx: master process /usr/sbin/nginx └─1628 nginx: worker process 2月 22 11:15:14 bogon systemd[1]: Starting The nginx HTTP and reverse prox..... 2月 22 11:15:14 bogon nginx[1622]: nginx: the configuration file /etc/ngin...ok 2月 22 11:15:14 bogon nginx[1622]: nginx: configuration file /etc/nginx/ng...ul 2月 22 11:15:15 bogon systemd[1]: Failed to parse PID from file /run/nginx...nt 2月 22 11:15:15 bogon systemd[1]: Started The nginx HTTP and reverse proxy...r. Hint: Some lines were ellipsized, use -l to show in full.
04、如果您的服务器受防火墙保护,则需要打开HTTP(80)和HTTPS(443)端口。
使用以下命令打开必要的端口:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
05、要验证您的Nginx安装,请在您选择的浏览器中打开http://YOUR_IP,您应该会看到默认的Nginx欢迎页面,如下图所示:
发表评论