nginx+tomcat配置https的方法

本文介绍了在nginx作为前端代理,tomcat处理请求的环境中,如何配置nginx以实现https,重点讲述了只在nginx层面配置https的方法,包括修改nginx.conf文件和调整tomcat的server.xml,以及重启服务的步骤。
摘要由CSDN通过智能技术生成

nginx+tomcat配置https的方法

场景

开发过小程序的都知道,小程序里规定了必须使用https协议。而我的服务器是使用nginx做前端代理分发,tomcat处理请求。

因此,需要在nginx反向代理tomcat的基础上配置https。

方法

nginx+tomcat配置https的方法有两种:

  • nginx配置https,tomcat也配置https

  • nginx配置https,tomcat采用http

本文使用的是第二种方法,关于第一种方法可以参考(不保证正确):https://www.jb51.net/article/131766.htm

1.配置nginx

打开*/nginx/conf/nginx.conf,修改成如下:

#注意:不需要的语句最好不要删除,使用#注释即可
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
   
    keepalive_timeout  65;

    upstream tomcat {
        server 127.0.0.1:8080 weight=1;
    }

    #gzip  on;

    # HTTP server
    server {
        listen       80;
        server_name  www.amongthecrowd.cn;
        rewrite ^(.*)$ https://$host$1 permanent;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }


    # HTTPS server
    #
    server {
       listen       443 ssl;
       server_name  www.amongthecrowd.cn;

       ssl 
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值