云服务器 nginx + tomcat 部署集群 配置

时间:2023-03-10 00:10:22
云服务器 nginx + tomcat 部署集群 配置

nginx.conf

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; upstream tomcats {
server 10.154.49.196:;
} upstream tomcats-quartz {
server 10.154.49.196:;
} server {
listen ;
server_name www.itzixi.com; #itzixi.com;
access_log /home/wwwlogs/www.itzixi.com_nginx.log combined;
root /home/wwwroot/www.itzixi.com;
index index.html index.htm index.jsp index.action index; #rewrite ^(.*)$ https://$host$1 permanent; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
} location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
} location ~ { #/ {
proxy_pass http://tomcats; # open tomcat servera
include proxy.conf;
} } # ssl(https) config
# server {
# listen ;
# server_name www.itzixi.com; # itzixi.com;
# access_log /home/wwwlogs/www.itzixi.com_nginx.log combined;
# root /home/wwwroot/www.itzixi.com;
# index index.html index.htm index.jsp index.action index;
#
# location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
# expires 30d;
# access_log off;
# }
#
# location ~ .*\.(js|css)?$ {
# expires 7d;
# access_log off;
# }
#
# ssl on;
# ssl_certificate 1_www.itzixi.com_bundle.crt;
# ssl_certificate_key 2_www.itzixi.com.key;
# ssl_session_timeout 5m;
# ssl_protocols TLSv1 TLSv1. TLSv1.;
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
# ssl_prefer_server_ciphers on;
# location ~ { #/ {
# proxy_pass http://tomcats; # open tomcat server
# include proxy.conf;
# }
#
# } # image server
server {
listen ;
server_name localhost;
#server_name www.itzixi.com itzixi.com; location /group1/M00 {
ngx_fastdfs_module;
}
} }

proxy.conf

proxy_connect_timeout 300s;
proxy_send_timeout ;
proxy_read_timeout ;
proxy_buffer_size 32k;
proxy_buffers 64k;
proxy_busy_buffers_size 128k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

server.xml,注释掉原来的host,加入下面这行

<Host name="localhost" appBase="" unpackWARs="true" autoDeploy="true"> 

      <Context path=""
docBase="/home/wwwroot/www.itzixi.com"
reloadable="false"
crossContext="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs"
prefix="www.itzixi.com_access_log"
suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

项目从war包解压后放入此目录:

/home/wwwroot/www.itzixi.com