奇忠诚 发表于 2016-12-24 10:56:52

nginx+tomcat中server配置

  一般利用nginx做代理,在nginx.conf中

server {
listen       80;
server_namelocalhost;
root   /home/mysite/public_html;
location / {
indexindex.html index.htmindex.jsp;
}
location ~ .*.jsp$
{
index index.jsp;
proxy_pass http://localhost:8080;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
proxy_set_headerHost$http_host;
}

location ~ \.action$ {
proxy_pass http://localhost:8080;
proxy_set_header      X-Real-IP $remote_addr;
proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header      Host $http_host;
}
location ~ ^/WEB-INF/* {
proxy_pass http://localhost:8080;
proxy_set_header      X-Real-IP $remote_addr;
proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header      Host $http_host;
}
error_page   500 502 503 504/50x.html;
location = /50x.html {
root   html;
}
}
  
这种方式需要服务器开两个端口,一是80,二是8080。
  还有一种请求配置方法:

location ~ .*.$ { #所有jsp页面以及do/action请求均交由tomcat处理


    index index.jsp;


    proxy_pass http://localhost:8080; #转向tomcat处理


}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { #设定访问静态文件直接读取不经过tomcat

    expires      30d;


}

location ~ .*\.(js|css)?$ {

    expires      1h;


}
页: [1]
查看完整版本: nginx+tomcat中server配置