使域名跳转至SpringBoot设置的content-path路径

  在使用SpringBoot开发的一个系统时设置了content-path,后来临时需要使域名能够跳转到一个指定的路径上,但是直接访问域名时打开是404,必须依照配置的RequestMapping打开才行。举个例子,某个网页的路径是 http://vpsname.com/webpage/index,配置后可以通过打开 http://vpsname.com/ 跳转到 http://vpsname.com/webpage/index 。在尝试一些配置之后放弃了对SpringBoot的配置,下面简述一下我的解决方案。

  方法很简单,就是通过nginx,根据访问的路径进行映射,因为nginx和springboot都运行在同一台服务器上,所以只需要映射到本地+端口即可。对于域名的访问指向本地的index.html,再html页面内设置自动跳转即可。

        location /webpage/ {
            proxy_pass http://localhost:8080/webpage/;
        }

        location / {
            root   html;
            index  index.html index.htm;
        }

  通过上面的nginx配置后,打开 http://vpsname.com/ 即可跳转至 http://vpsname.com/webpage/index 页面。

  目前暂时没有更好的方法,如果有更好的方法或建议,欢迎指正!

 

* 以上链接仅做举例使用。

posted @ 2020-05-19 21:40  Maolic  阅读(3220)  评论(0编辑  收藏  举报