CentOS安装Nginx

一、Nginx安装

1.添加Nginx到yum源

1
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.安装nginx

1
yum install -y nginx

3.启动nginx

1
systemctl start nginx.service

4.设置开机启动

1
systemctl enable nginx.service

5. 停止开机自启动

1
systemctl disable nginx.service

6.查看服务当前状态

1
systemctl status nginx.service

7.重启Nginx服务

1
systemctl restart nginx.service

8.查看所有已启动的服务

1
systemctl list-units --type=service

二、防火墙配置

1.防火墙打开80端口

1
firewall-cmd --zone=public --add-port=80/tcp --permanent

参数说明:

–zone #作用域

–add-port=80/tcp #添加端口,格式为:端口/通讯协议

–permanent #永久生效,没有此参数重启后失效

2.重启防火墙生效

1
firewall-cmd --reload

三、常用目录

网站文件存放默认目录  /usr/share/nginx/html

网站默认站点配置  /etc/nginx/conf.d/default.conf

自定义Nginx站点配置文件存放目录  /etc/nginx/conf.d/

Nginx全局配置  /etc/nginx/nginx.conf

四、Nginx配置

1.配置端口转发80转到8092,配置后重启Nginx

1
vi /etc/nginx/conf.d/default.conf

img