一、Nginx安装
1.添加Nginx到yum源
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.安装nginx
yum install -y nginx
3.启动nginx
systemctl start nginx.service
4.设置开机启动
systemctl enable nginx.service
5. 停止开机自启动
systemctl disable nginx.service
6.查看服务当前状态
systemctl status nginx.service
7.重启Nginx服务
systemctl restart nginx.service
8.查看所有已启动的服务
systemctl list-units --type=service
二、防火墙配置
1.防火墙打开80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
参数说明:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
2.重启防火墙生效
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转到8090,配置后重启Nginx
vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:8090;
}
}
评论区