nginx+tomcat集群+https

nginx+tomcat集群

一、nginx安装

1、安装nginx需要的依赖包
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2、下载nginx安装包
wget http://nginx.org/download/nginx-1.16.1.tar.gz

tar -xvf nginx-1.16.1.tar.gz

3、nginx安装
cd ./nginx-1.16.1/

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module

//编译安装
make && make install
4、nginx配置文件路径

/usr/local/nginx/conf/nginx.conf

5、检测是否安装成功

/usr/local/nginx/sbin/nginx

命令作用
nginx启动服务
nginx -s reload重载服务
nginx -s stop停止服务

在这里插入图片描述

二、tomact安装

1、下载
cd /usr

wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.96/bin/apache-tomcat-7.0.96.tar.gz

//解压缩
tar -xvf  apache- tomcat-7.0.96.tar.gz

//重命名为 tomcat7
 mv apache-tomcat-7.0.96 tomcat7
 
//启动测试
/usr/tomcat7/bin/startup.sh

//访问localhost:8080 ,测试是否安装成功

2、集群tomcat的配置

vi /usr/tomcat7/webapps/ROOT/index.jsp

//复制一份tomcat

 cp -r tomcat7 ./tomcat7-1
 vi ./tomcat7-1/webapps/ROOT/index.jsp

修改Home为8081,方便标识

修改tomcat7-1的配置文件(共三处)
<Server port="8006" shutdown="SHUTDOWN">

<Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />


<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

三、nginx配置 http集群

1、修改nginx 配置文件

vi /usr/local/nginx/conf/nginx.conf //添加如下信息

   #gzip  on;
upstream mytomcats{
	  server localhost:8080 weight=1; #weight权重
      server localhost:8081 weight=1;
     }
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass http://mytomcats;
        }
2、重载nginx
访问localhost 测试是否可以达到负载 刷新页面,Home8080或者Home8081交替变化,(默认负载均衡策略:轮询

四、同时支持http和https

证书需手动申请,放置到服务器目录下,可用 acme.sh 申请免费证书

server {
        listen       443 ssl;
        server_name  你的域名或ip;

        ssl_certificate      /ca/server/server.crt;
        ssl_certificate_key  /ca/server/server.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   html;
            index  index.html index.htm;
                proxy_pass http://mytomcats;
        }
    }

五、强制https

server {
listen 80;
server_name 域名或ip;
#rewrite ^(.*) https://$server_name$1 permanent;
rewrite ^(.*)$  https://$host$1 permanent;
}

六、关闭404无用日志

在server{…}添加如下内容

location = /favicon.ico {
log_not_found off;
access_log off;
}

七、参考内容

https://www.cnblogs.com/saneri/p/5391821.html
https://www.cnblogs.com/fengyuduke/p/11232662.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值