博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx + Tomcat + HTTPS+负载均衡
阅读量:5916 次
发布时间:2019-06-19

本文共 3600 字,大约阅读时间需要 12 分钟。

  hot3.png

1.nginx 负载均衡配置 upstream tomcat_server {

        ip_hash;
        server 127.0.0.1:8081 weight=1;
        server 127.0.0.1:8082 weight=1;
} 2.nginx 配置 server { listen 80; server_name crm.xx.cn www.crm.xx.cn; if ($scheme != https) { # 强制 HTTP 跳转至 HTTPS # host 与 server_name 等价, redirect/permanent 分别为临时跳转/永久跳转 rewrite ^(.*)$ https://$server_name$1 permanent; } } server { listen 443 ssl; ssl on; server_name xx.cn www.xx.cn;

location / {        #每个请求按照ip的hash结果分配,同一个ip的访客固定访问一个后端服务器,可解决动态网页session共享问题        proxy_next_upstream http_502 http_504 error timeout invalid_header;        proxy_set_header        Host $host;        proxy_set_header        X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;         proxy_set_header X-Forwarded-Proto  $scheme;  				proxy_http_version 1.1;		proxy_connect_timeout 5s;		proxy_read_timeout 10800s;		proxy_send_timeout 12s;        proxy_set_header Upgrade $http_upgrade;        proxy_set_header Connection "upgrade";		client_max_body_size  100m;        proxy_pass http://tomcat_server;    }location /preview {		proxy_next_upstream http_502 http_504 error timeout invalid_header;        proxy_set_header        Host $host;        proxy_set_header        X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;         proxy_set_header X-Forwarded-Proto  $scheme;  		proxy_http_version 1.1;		proxy_connect_timeout 5s;		proxy_read_timeout 10800s;		proxy_send_timeout 12s;        proxy_set_header Upgrade $http_upgrade;        proxy_set_header Connection "upgrade";        proxy_pass http://localhost:8080;} #配置Nginx动静分离,定义的静态页面直接从Nginx发布目录读取location ~ /upload/.*\.(png|jpg)$ { 		 #每个请求按照ip的hash结果分配,同一个ip的访客固定访问一个后端服务器,可解决动态网页session共享问题        proxy_next_upstream http_502 http_504 error timeout invalid_header;        proxy_set_header        Host $host;        proxy_set_header        X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;         proxy_set_header X-Forwarded-Proto  $scheme;  		proxy_http_version 1.1;		proxy_connect_timeout 5s;		proxy_read_timeout 10800s;		proxy_send_timeout 12s;        proxy_set_header Upgrade $http_upgrade;        proxy_set_header Connection "upgrade";		client_max_body_size  100m;        proxy_pass http://tomcat_server;  }  location ~ /preview/.*\.(png|jpg)$ { 		 #每个请求按照ip的hash结果分配,同一个ip的访客固定访问一个后端服务器,可解决动态网页session共享问题       proxy_next_upstream http_502 http_504 error timeout invalid_header;        proxy_set_header        Host $host;        proxy_set_header        X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;         proxy_set_header X-Forwarded-Proto  $scheme;  		proxy_http_version 1.1;		proxy_connect_timeout 5s;		proxy_read_timeout 10800s;		proxy_send_timeout 12s;        proxy_set_header Upgrade $http_upgrade;        proxy_set_header Connection "upgrade";        proxy_pass http://localhost:8080;  }   location ~ .*\.(js|css|png|jpg)$ { 		root html/static;		#expires定义用户浏览器缓存的时间为3天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力		if (-f $request_filename) { 			expires 3d;		}   } ssl_certificate   /home/nginx/crmcert/xxxx.pem; ssl_certificate_key  /home/nginx/crmcert/xxxxx.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; }3 tomcat server.xml 配置找到

然后修改HOST里的value值,我这里修改为 <Host name="xx.cn" appBase="webapps" <!--这里的name要与nginx配置文件里的server_name保持一致--> unpackWARs="true" autoDeploy="true">

转载于:https://my.oschina.net/bozhi/blog/1922201

你可能感兴趣的文章
android 获取系统默认路径
查看>>
关于移动设备网页资料
查看>>
Highcharts API中英对照查询表
查看>>
Docker 网络管理
查看>>
repaint和reflow的相关知识
查看>>
android系统信息总结
查看>>
个国内速度最快的centos yum(更新源)
查看>>
phantomjs处理异步加载后,获取渲染后的页面源码
查看>>
varnish 简介以及实用配置
查看>>
Python中pyc文件的用途
查看>>
eclipse调试远程Tomact
查看>>
[Swift]快速排序算法
查看>>
presto中的名词
查看>>
【致青春】开垦出的IT路
查看>>
解决apache服务器下载.dmg文件乱码页码问题
查看>>
四种方案解决ScrollView嵌套ListView问题
查看>>
实例讲解PAT配置
查看>>
centos下network和NetworkManager冲突的解决方法
查看>>
Mac OS上搭建Apache+PHP+MySQL开发环境的详细教程
查看>>
ccnp大型企业综合案例分析2
查看>>