阿里云linux服务器,JAVA controller怎么获取不到当前的域名?

如题

String url2=request.getScheme()+"://"+ request.getServerName();
        System.out.println("协议名://域名="+url2);

        StringBuffer url = request.getRequestURL();
        String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append("/").toString();
        System.out.println("=========无上下文============"+tempContextUrl);

        StringBuffer url3 = request.getRequestURL();
        String tempContextUrl3 = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/")
                .toString();
        System.out.println("=========上下文============"+tempContextUrl3);


我用上面的三个方法,获取到的都是http://127.0.0.1

我想要拿 https://www.a.com怎么拿

nginx 配置:
location ~ ^/(xxx) {
     proxy_set_header x-forwarded-for  $remote_addr; 
     proxy_pass http://localhost:8988;
}


proxy_set_header Host $host; 加上这个我能拿到http://www.a.com
问题二:我浏览器输入的是https://www.a.com 这个https我怎么设置啊?????
阅读 2.3k
1 个回答

location里面加 proxy_set_header Host $host;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题