Nginx proxy Tomcat problem
为情所困
为情所困 2017-05-16 17:23:33
0
1
446

The following two solutions, I don’t know if my configuration is wrong or something. After the first configuration, it consumes a lot of resources, especially when starting Tomcat for the first time, the basic one cannot be started. The second There is no problem with the second type, but there is a problem with the second type. If it is

I visit http://kaipizhe.com At this time request.getRequestURI(); this value is /kaipizhe/ instead of /
When I visit http://kaipizhe.com/all/ this time request.getRequestURI(); the value is /kaipizhe/all/ instead of /all/

See this question specifically: link description



Option One:

Nginx Configuration:

nginxserver
{
    listen       80;  
    server_name  kaipizhe.com;
    root  /usr/local/tomcat/webapps/kaipizhe;

    include none.conf;

    location / {
            proxy_pass http://localhost:8080/;
            proxy_cookie_path / /;
            proxy_set_header   Host    $host;
            proxy_set_header   X-Real-IP   $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect http://localhost:8080/ http://kaipizhe.com/;
        }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

    location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

    access_log  /home/wwwlogs/kaipizhe.com.log  kaipizhe.com;
}

Tomcat server.xml Configuration:

xml<Host name="kaipizhe.com" appBase="kaipizhe"
    unpackWARs="true" autoDeploy="true"
    xmlValidation="false" xmlNamespaceAware="false">
    <alias>kaipizhe.com</alias>

  <Context docBase="/usr/local/tomcat/webapps/kaipizhe" path="/" reloadable="true" />
</Host>


Option II:

Nginx Configuration:

nginxserver
{
    listen       80;  
    server_name  kaipizhe.com;
    root  /usr/local/tomcat/webapps/kaipizhe;

    include none.conf;

    location / {
            proxy_pass http://localhost:8080/kaipizhe/;
            proxy_cookie_path /kaipizhe /;
            proxy_set_header   Host    $host;
            proxy_set_header   X-Real-IP   $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect http://localhost:8080/kaipizhe/ http://kaipizhe.com/;
        }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

    location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

    access_log  /home/wwwlogs/kaipizhe.com.log  kaipizhe.com;
}

Tomcat server.xml Do not modify, that is, do not add Host

为情所困
为情所困

reply all(1)
仅有的幸福

It should be a problem with tomcat. Check the tomcat startup log to see if there is any error message.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template