Apache/Tomcat error - wrong pages being delivered

后端 未结 11 881
借酒劲吻你
借酒劲吻你 2020-12-09 05:51

This error has been driving me nuts. We have a server running Apache and Tomcat, serving multiple different sites. Normally the server runs fine, but sometimes an error happ

相关标签:
11条回答
  • 2020-12-09 06:33

    I had this problem and it really drove me nuts. I dont know why, but I solved it turning off the Keep Alive on the http.conf

    from

    KeepAlive On

    to

    KeepAlive Off

    My application doesn't use the keepalive feature, so it worked very well for me.

    0 讨论(0)
  • 2020-12-09 06:39

    Are you sure that is the page that somebody else requested or a page without parameters?, you could get weird errors if your connectionTimeout is too short at server.xml on the tomcat server behind apache, increase it to a bigger number:

    default configuration:

      <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
    

    changed:

      <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="2000000"
                   redirectPort="8443" />
    
    0 讨论(0)
  • 2020-12-09 06:41

    Could it be the thread-safety of your servlets?

    Do your servlets store any information in instance members.

    For example, something as simple as the following may cause thread-related issues:

    public class MyServlet ... {
        private String action;
    
        public void doGet(...) {
             action = request.getParameter("action");
             processAction(response);
        }
    
        public void processAction(...) {
             if (action.equals("foo")) {
                 // send foo page
             } else if (action.equals("bar")) {
                 // send bar page
             }
         }
    }
    

    Because the serlvet is accessed by multiple threads, there is no guarantee that the action instance member will not be clobbered by someone elses request, and end up sending the wrong page back.

    The simple solution to this issue is to use local variables insead of instance members:

    public class MyServlet ... {
        public void doGet(...) {
             String action = request.getParameter("action");
             processAction(action, response);
        }
    
        public void processAction(...) {
             if (action.equals("foo")) {
                 // send foo page
             } else if (action.equals("bar")) {
                 // send bar page
             }
         }
    }
    

    Note: this extends to JavaServer Pages too, if you were dispatching to them for your views?

    0 讨论(0)
  • 2020-12-09 06:41

    We switched Apache from proxying with AJP to proxying with HTTP. So far it appears to have solved the issue, or at least vastly reduced it - the problem hasn't been reported in months, and the app's use has increased since then.

    The change is in Apache's httpd.conf. Having started with mod_jk:

    JkMount /portal ajp13
    

    We switched to mod_proxy_ajp:

    ProxyPass /portal ajp://localhost:8009/portal
    

    Then finally to straight mod_proxy:

    ProxyPass /portal http://localhost:8080/portal
    

    You'll need to make sure Tomcat is set up to serve HTTP on port 8080. And remember that if you're serving /, you need to include / on both sides of the proxy or it starts crying:

    ProxyPass / http://localhost:8080/
    
    0 讨论(0)
  • 2020-12-09 06:43

    Have a look at this site, it describes an issue with mod_jk. I came accross your posting while looking at a very similar issue. Basically the fix is to upgrade to a newer version of mod_jk. I haven't had a chance to implement the change in our server yet, but I'm going to try this tomorrow and see if it helps.

    http://securitytracker.com/alerts/2009/Apr/1022001.html

    0 讨论(0)
提交回复
热议问题