在nginx中配置一个二级域名到一个springboot项目,其中有一个静态目录用于前端展示。为了跨域与方便之类的问题,这个项目被安排到了springboot的静态目录中。但是在访问的过程中,总是访问 域名/目录 是这种形式有点不友好。于是在nginx中进行了一些配置。
将h5下的页面直接返回到域名根目录,但是发现,直接访问域名的话,会返回404。
于是添加如下配置,将 / 转向到 /index.html
upstream test {
server 127.0.0.1:8080;
}
server {
#新增的项目域名
server_name new.test.com;
index index.html;
location /image {
alias /data/test/;
}
#后台管理
location /admin/ {
client_max_body_size 50m;
proxy_pass http://test/admin/;
}
#rest接口
location /rest/ {
proxy_pass http://test/rest/;
}
#在这里将根目录直接返回到index.html
location = / {
rewrite ^ /index.html permanent;
}
location / {
proxy_pass http://test/h5/;
}
}
经过测试,达到效果。
====================
作者:ckun
链接:https://ckun.xyz/2019/06/nginx配置二级域名反向代理配置主页/
来源:C君的代码备忘
转载请联系作者获得授权并注明出处。
留言