一、Tomcat多实例部署
1、创建一个项目目录
2、修改Tomcat配置文件 conf目录下server.xml文件 appBase="项目路径"
3、修改Tomcat端口 conf目录下server.xml文件,默认端口为 8005,8080,8009这三个端口都要变更,不存在重复
<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
4、启动Tomcat bin目录下startup.sh 执行命令并查看日志./startup.sh & tailf ../logs/catalina.out
5、浏览器验证输入你的IP和端口,跟上你的项目名称等,验证是否OK
二、Tomcat配置反问日志,使访问日志显示请求耗时
修改conf目录server.xml文件
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b %T" />
%T请求耗时,单位秒
三、nginx反向代理
nginx优点 1、可以存放静态资源 2、可以做负载均衡 3、可以做反向代理
1、nginx配置文件配置
upstream tomcat_teach {
server 127.0.0.1:8080 weight=10 max_fails=2 fail_timeout=30s; server 127.0.0.1:8082 weight=30 max_fails=2 fail_timeout=30s;
# weight 权重 请求分配 max_fails 失败次数,超过不请求 fail_tiameout 超时时间 } server { listen 80; #监听端口 server_name www.teach.com; #域名 access_log /export/servers/nginx/logs/access.log main; #项目日志 error_log /export/servers/nginx/logs/error.log warn; chunkin on; error_page 411 = @my_error; location @my_error { chunkin_resume; } root /export/apps/; location / { proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://tomcat_teach; expires 1d; } location /logs/ { autoindex off; deny all; } }
2、启动nginx