nginx tomcat 动静分离配置



nginx tomcat 动静分离配置_第1张图片



        location / {
                    proxy_pass http://127.0.0.1:8080;
                    # 真实的客户端IP
                    proxy_set_header   X-Real-IP        $remote_addr;
                    # 请求头中Host信息
                    proxy_set_header   Host             $host;
                    # 代理路由信息,此处取IP有安全隐患
                    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                    # 真实的用户访问协议
                    proxy_set_header   X-Forwarded-Proto $scheme;
                    index  index.html index.htm;
        }
        #静态文件交给nginx处理
        location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$

            {

                    #静态资源位置

                    root  /usr/local/tomcat/webapps/ROOT;         

                   #缓存时间  3天

                   expires 3d;

            }
        #静态文件交给nginx处理
        location ~ .*\.(js|css)?$
            {

                    root /usr/local/tomcat/webapps/ROOT;

                   #缓存时间  6小时

                    expires 6h;
            }
    }

nginx tomcat 动静分离配置_第2张图片



        location / {
                    proxy_pass http://127.0.0.1:8080;
                    # 真实的客户端IP
                    proxy_set_header   X-Real-IP        $remote_addr;
                    # 请求头中Host信息
                    proxy_set_header   Host             $host;
                    # 代理路由信息,此处取IP有安全隐患
                    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                    # 真实的用户访问协议
                    proxy_set_header   X-Forwarded-Proto $scheme;
                    index  index.html index.htm;
        }
        #静态文件交给nginx处理
        location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$

            {

                    #静态资源位置

                    root  /usr/local/tomcat/webapps/ROOT;         

                   #缓存时间  3天

                   expires 3d;

            }
        #静态文件交给nginx处理
        location ~ .*\.(js|css)?$
            {

                    root /usr/local/tomcat/webapps/ROOT;

                   #缓存时间  6小时

                    expires 6h;
            }
    }

你可能感兴趣的:(nginx tomcat 动静分离配置)