Centos8安装nginx - zhangxiulin/RuoYi-Vue GitHub Wiki

1.使用yum安装nginx
[root@iZ8vb39159pi4f9hurhnbyZ ~]# yum install nginx -y

2.查看nginx安装目录
[root@iZ8vb39159pi4f9hurhnbyZ ~]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz
由上述信息可知,配置文件位置为 /etc/nginx

3.到/etc/nginx下备份并修改配置文件
[root@iZ8vb39159pi4f9hurhnbyZ ~]# cd /etc/nginx/
[root@iZ8vb39159pi4f9hurhnbyZ ~]# cp nginx.conf nginx.conf.bak
[root@iZ8vb39159pi4f9hurhnbyZ ~]# vi nginx.conf
在 server 节点内添加如下配置
location / {
root /home/ruoyi/projects;
index hello.html;
}

4.启动nginx
[root@iZ8vb39159pi4f9hurhnbyZ ~]# systemctl restart nginx.service
[root@iZ8vb39159pi4f9hurhnbyZ ~]# ps -ef|grep nginx

配置location proxy_pass 后面的url加与不加 / 的区别。
场景: 我们请求的地址为 http://x.x.x.x/prod-api/a
nginx配置文件如下:
server{
port 80,

location /prod-api{ proxy_pass http://localhost:8080; }

location /prod-api{ proxy_pass http://localhost:8080/ }

location /prod-api/{ proxy_pass http://localhost:8080 }

location /prod-api/{ proxy_pass http://localhost:8080/ }
}
第一种:location后没有/ 转发网站没有/
最后网址经过nginx转向到的网址是 http://x.x.x.x:8080/prod-api/a

第二种:location后没有/ 转发网站有/
最后网址经过nginx转向到的网址是 http://x.x.x.x:8080/a

第三种:location后有/ 转发网站没有/
最后网址经过nginx转向到的网址是 http://x.x.x.x:8080/prod-api/a

第四种:location后有/ 转发网站有/
最后网址经过nginx转向到的网址是 http://x.x.x.x:8080/a

⚠️ **GitHub.com Fallback** ⚠️