Darui's blog

Home | About | Contacts | Archive

Contos7下安装nginx

配置 EPEL源

[root@localhost ~]# sudo yum install -y epel-release
[root@localhost ~]# sudo yum -y update

安装Nginx

[root@localhost ~]# sudo yum install -y nginx

安装成功后,默认的网站目录为: /usr/share/nginx/html

默认的配置文件为:/etc/nginx/nginx.conf

自定义配置文件目录为: /etc/nginx/conf.d/

开启端口80和443

如果你的服务器打开了防火墙,你需要运行下面的命令,打开80和443端口。

[root@localhost ~]# sudo firewall-cmd --permanent --zone=public --add-service=http
[root@localhost ~]# sudo firewall-cmd --permanent --zone=public --add-service=https
[root@localhost ~]# sudo firewall-cmd --reload

如果你的服务器是阿里云ECS,你还可以通过控制台安全组,打开80和443端口,或者其他自定义端口。

操作Nginx

1.启动 Nginx

[root@localhost ~]# systemctl start nginx

2.停止Nginx

[root@localhost ~]# systemctl stop nginx

3.重启Nginx

[root@localhost ~]# systemctl restart nginx

4.查看Nginx状态

[root@localhost ~]# systemctl status nginx

5.启用开机启动Nginx

[root@localhost ~]# systemctl enable nginx

6.禁用开机启动Nginx

[root@localhost ~]# systemctl disable nginx
Category: contos7
Tags: [ contos7  nginx  ]

Darui's blog | 鲁ICP备 15018213号-1 | 本站作品采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可。 | Build with Github and true minimal theme