1:安装tomcat
2:安装nginx
3:配置nginx的配置文件:conf.d/ 下面的指定配置文件
例如:
upstream tomcat {
ip_hash;
server 127.0.0.1:8080;
}
server {
listen 80;
server_name _;
access_log /data/logs/nginx/lawyer_access.log main;
error_log /data/logs/nginx/lawyer_error.log;
index html.html index.html index.shtml index.jsp home.html;
rewrite ^/index.php/(.*)$ /index.php?s=$1 last;
#指到tomcat的webapps下,然后配置tomcat的service.xml文件更改tomcat的默认访问目录
root /omcat/webapps;
if ($request_uri ~ " ") {
return 444;
}
location ~ .*\.svn\/.* { return 405; }
# location ~ .*.jsp$ { #注意这里写的如果是jsp/nginx就只会转发jsp的请求/其余的请求一概会出现404
location / { # / 代表转发所有类型请求
proxy_pass http://tomcat; #主要在这里,设置一个代理
}
location ~* \.(html|shtml|htm|inc|log)$ {
expires 1m;
}
location ~* \.(css|js)$ {
expires 1m;
}
location ~* ^.+\.(jpg|jpeg|gif|swf|mpeg|mpg|mov|flv|asf|wmv|avi|ico)$ {
expires 15d;
}
}
4:配置tomcat的service.xml配置文件,更改默认访问项目路径
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- 手动添加一行Contenxt 节点 配置docBase参数为tomcat访问参数-->
<Context path="" docBase="/tomcat/webapps/project" debug="0" reloadable="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
5:重启nginx和tomcat