标签:mp3 add proc connector bin 进入 use notice app
利用nginx对请求进行分流,将请求平均的分给不同的tomcat去处理,减少单个tomcat的负载量,提高tomcat的响应速度。
① 先安装配置好1个tomcat服务器
安装tomcat: http://www.cnblogs.com/origalom/p/7643425.html
以普通用户运行tomcat:http://www.cnblogs.com/origalom/p/7666897.html
② 将安装好的tomcat复制一份
1 cd /usr/local/tomcat/ # 进入tomcat所在目录 2 cp -r tomcat8080/ tomcat8081 # 复制一份新的tomcat 3 chown -R tomcat:tomcat tomcat8081/ # 修改tomcat目录的所有者
③ 修改daemon.sh
如果在创建tomcat时,在daemon.sh中设置了CATALINA_HOME等变量,则新拷贝的tomcat需要将这些变量设置成新的地址。
④ 修改端口,让新的tomcat可以正常运行
vim tomcat8081/conf/server.xml
修改tomcat内部的端口,使用一个未使用的端口号,一般可以往上加一:
第22行的8005端口: <Server port="8005" shutdown="SHUTDOWN">
第69行的8080端口:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
第116行的8009端口: <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
⑤ 修改tomcat项目的运行根目录
修改server.xml,将148行的appBase中的webapps改成项目所在地址:
<Host name="localhost" appBase="/usr/local/tomcat/tomcat8080/webapps"
unpackWARs="true" autoDeploy="true">
⑥ 启动tomcat,检查是否启动成功
sudo tomcat8081/bin/daemon.sh start
配置nginx.conf配置文件。
1 user nginx; 2 worker_processes 1; 3 4 error_log logs/error.log; 5 error_log logs/error.log notice; 6 error_log logs/error.log info; 7 8 pid logs/nginx.pid; 9 10 11 events { 12 worker_connections 1024; 13 } 14 15 16 http { 17 include mime.types; 18 default_type application/octet-stream; 19 20 #log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ 21 # ‘$status $body_bytes_sent "$http_referer" ‘ 22 # ‘"$http_user_agent" "$http_x_forwarded_for"‘; 23 24 #access_log logs/access.log main; 25 26 server_names_hash_bucket_size 256; 27 fastcgi_connect_timeout 300; 28 fastcgi_send_timeout 300; 29 fastcgi_read_timeout 300; 30 fastcgi_buffer_size 64k; 31 fastcgi_buffers 8 128k; 32 fastcgi_busy_buffers_size 256k; 33 fastcgi_temp_file_write_size 256k; 34 server_tokens off; 35 send_timeout 60; 36 sendfile on; 37 tcp_nopush on; 38 tcp_nodelay on; 39 keepalive_timeout 65; 40 client_header_timeout 3m; 41 client_body_timeout 3m; 42 client_max_body_size 2000m; 43 gzip on; 44 45 # tomcat集群 46 # 47 upstream tomcat { 48 server 127.0.0.1:8080; 49 server 127.0.0.1:8081; 50 } 51 52 53 # HTTPS服务器 54 # 55 server { 56 listen 80; 57 listen 443 ssl; 58 server_name www.origal.cn; 59 60 ssl_certificate /usr/local/nginx/conf/ssl/214324938610703.pem; 61 ssl_certificate_key /usr/local/nginx/conf/ssl/214324938610703.key; 62 ssl_session_cache shared:SSL:1m; 63 ssl_session_timeout 5m; 64 ssl_ciphers HIGH:!aNULL:!MD5; 65 ssl_prefer_server_ciphers on; 66 67 location / { 68 index index.jsp; 69 70 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 71 proxy_set_header Host $http_host; 72 proxy_set_header X-Forwarded-Proto https; 73 proxy_redirect off; 74 client_max_body_size 500m; 75 client_body_buffer_size 3m; 76 proxy_connect_timeout 90; 77 proxy_read_timeout 90; 78 proxy_buffer_size 4k; 79 proxy_buffers 6 32k; 80 proxy_busy_buffers_size 64k; 81 proxy_temp_file_write_size 64k; 82 83 if (!-e $request_filename) { 84 proxy_pass http://tomcat; 85 } 86 } 87 88 # 静态资源直接访问 89 location ~ \.(js|css|png|gif|jpg|jpeg|mp4|mp3|mpg|3gp|txt)$ { 90 root /usr/local/java/tomcat8080/webapps/; 91 if (!-e $request_filename) { 92 proxy_pass http://tomcat; 93 } 94 } 95 } 96 }
标签:mp3 add proc connector bin 进入 use notice app
原文地址:http://www.cnblogs.com/origalom/p/7821677.html