Problem with GWT behind a reverse proxy - either nginx or apache

前端 未结 7 578
悲&欢浪女
悲&欢浪女 2020-12-15 22:20

I\'m having this problem with GWT when it\'s behind a reverse proxy. The backend app is deployed within a context - let\'s call it /context.

The GWT app works fine

7条回答
  •  别那么骄傲
    2020-12-15 22:49

    Michele,

    Thank you for the example servlet to handle this problem. However when I tried to use your approach it worked in the reverse proxy environment but not in my dev mode eclipse environment.

    I took an approach that would let me seamlessly move between my dev and prod environments.

    As you did I overwrote RemoteServiceServlet but I only replaced following...

    @Override
    protected SerializationPolicy doGetSerializationPolicy(
            HttpServletRequest request, String moduleBaseURL, String strongName) {
        //get the base url from the header instead of the body this way 
        //apache reverse proxy with rewrite on the header can work
        String moduleBaseURLHdr = request.getHeader("X-GWT-Module-Base");
    
        if(moduleBaseURLHdr != null){
            moduleBaseURL = moduleBaseURLHdr;
        }
    
        return super.doGetSerializationPolicy(request, moduleBaseURL, strongName);
    }
    

    In my apache config I added...

    ProxyPass /app/ ajp://localhost:8009/App-0.0.1-SNAPSHOT/
    

    RequestHeader edit X-GWT-Module-Base ^(.*)/app/(.*)$ $1/App-0.0.1-SNAPSHOT/$2
    

    This approach works in all scenarios and delegates the url "mucking" to apache's proxy settings which is the approach I've always taken.

    Comments on this approach are appreciated

提交回复
热议问题