nginx和tomcat做动静分离其实很简单,在安装nginx和tomcat方面和平常安装一样,没有什么特别,安装教程可以参看本博客上的教程。安装好以后,就是配置,tomcat没什么好说的,改怎么配置就怎么配置,要做到动静分离,主要就是Nginx的配置,现在我贴下我nginx的配置文件
server
{
listen 80;
server_name www.ileiming.com;
root /usr/local/tomcat/www.ileiming.com;
index index.html index.jsp;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|txt)$
{
expires 7d;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.(jsp|jspx|do|action|amq)?$ {
root /usr/local/tomcat/www.ileiming.com;
index index.jsp;
proxy_pass http://127.0.0.1:8080; #tomcat端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
log_format www.ileiming.comlog '$remote_addr – $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log logs/www.ileiming.com.log www.ileiming.comlog;
}
红色标注部分就是说后缀名为jsp,jspx,do,action,amq的,都交给8080端口去处理,其他的就没什么好说的,保存访问,OK,一切正常
转载请注明:IT运维空间 » linux » Nginx Tomcat动静分离
发表评论