Nginx是一个高性能的web服务器软件。它与Apache HTTP Server比较,更加地灵活和轻量级。
本文介绍如何在CentOS7上使用yum安装Nginx。
执行如下命令配置Nginx官方仓库
cat > /etc/yum.repos.d/nginx.repo << EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
EOF
现在使用yum安装Nginx:
sudo yum -y install nginx
Nginx安装后不会自动启动,执行如下命令启动nginx
sudo systemctl start nginx
如何启用了firewall,执行如下命令来允许HTTP和HTTPS流量:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
这样你就可以在浏览器输入http://server_domain_name_or_IP/来访问nginx了,如图
sudo systemctl enable nginx