Skip to content

安装

centos为例。利用yum安装nginx

shell
#查看是否安装了nginx
yum list nginx

#安装nginx
sudo yum install nginx

#开机自启动
sudo systemctl enable nginx

#启动nginx
sudo systemctl start nginx

#重启nginx
sudo systemctl restart nginx

#重新加载nginx
sudo systemctl reload nginx

TIP

在使用sudo yum install nginx安装时,如果报错没有可用软件包nginx的话,执行下sudo yum install epel-release,然后再执行sudo yum install nginx。这是由于centos官方库中可能并没有nginx,需要在EPEL库中获取。

利用这种方式安装。默认的配置文件目录会是/etc/nginx/

nginx会默认配置80端口。安装完毕后,在浏览器中输入你的服务器IP地址,如果出现的页面有welcome to nginx或者welcome to centos等成功标志,证明安装并启动成功。

如果80端口的页面不能正常打开的话,可能是由于服务器有防火墙设置。像国内的阿里云与腾讯云,其安全组也可能会默认屏蔽80443端口。所以在服务器上执行下列代码,打开80443端口。

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