nginx多域名及https配置(Tomcat服务器)

article/2025/11/5 8:13:58

主域名配置

主域名配置
主域名https配置

二级域名配置

二级域名配置
二级域名https配置

详细配置

#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;#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  0;keepalive_timeout  65;gzip  on;server {#  listen       80;# server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# 主域名配置server {listen 80;server_name 主域名;index index.html;location / {proxy_pass http://127.0.0.1:8080;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 {listen 80;server_name 二级域名;index index.html;location / {proxy_pass http://127.0.0.1:8081;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}# 主域名https配置server {listen         443 ssl;server_name  主域名;  #网站域名,和80端口保持一致ssl             on;ssl_certificate E:\2846761.pem;       #证书公钥ssl_certificate_key  E:\2846761.key;  #证书私钥ssl_session_cache    shared:SSL:1m;ssl_session_timeout  5m;ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL;ssl_prefer_server_ciphers  on;location / {proxy_pass http://www.bjjkkj.com;proxy_redirect  off;     proxy_set_header        Host    $http_host;     proxy_set_header        X-Real-IP       $remote_addr;     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;     proxy_set_header   Cookie $http_cookie;#proxy_cookie_pathchunked_transfer_encoding       off;}}# 二级域名https配置server {listen         443 ssl;server_name  二级域名;  #网站域名,和80端口保持一致ssl             on;ssl_certificate E:\1684324.pem;       #证书公钥ssl_certificate_key  E:1684324.key;  #证书私钥ssl_session_cache    shared:SSL:1m;ssl_session_timeout  5m;ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL;ssl_prefer_server_ciphers  on;location / {proxy_pass http://i.bjjkkj.com;proxy_redirect  off;     proxy_set_header        Host    $http_host;     proxy_set_header        X-Real-IP       $remote_addr;     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;     proxy_set_header   Cookie $http_cookie;#proxy_cookie_pathchunked_transfer_encoding       off;}}server {listen         80;server_name    主域名;return         301 https://$server_name$request_uri;}server {listen         80;server_name    二级域名;return         301 https://$server_name$request_uri;}
}

  1. 查资料的过程中,有些资料说主域名配置https之后,二级域名会默认为https,配置过程中始终没有配置成功,目前使用的是一个域名对应一条https证书。
  2. 域名配置https时,需下载nginx的证书,且每个域名都会对应一套证书
--------- 存在不足之处,烦请批评指正,互相学习!!!--------

http://chatgpt.dhexx.cn/article/CeRUbpj5.shtml

相关文章

IIS配置HTTPS

1,新建网站,选中类型为 https,然后更改SSL证书为你配置的SSL证书, 对于SSL证书的配置是这样的 点开第二步,然后点击 创建自签名证书 确定以后点开网站看到有个SSL, 双击进去,再选中 要求SS…

配置HTTPS全过程

HTTPS配置全过程 服务器配置https协议 HTTPS,是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。 配置HTTPS就需要证书,关于证书方面不做过多…

linux配置https

背景说明 服务器为阿里云 ecs,操作系统为 centos 6.5。 部署配置说明 第一步,安装nginx 之所以要先安装 nginx,是因为下面配置域名解析的时候可以直接在浏览器看到效果,当然了,先配置域名,然后 ping 一…

nginx配置https访问

01、http&https HTTP(HyperText Transfer Protocol:超文本传输协议)是一种用于分布式、协作式和超媒体信息系统的应用层协议。 简单来说就是一种发布和接收 HTML 页面的方法,被用于在 Web 浏览器和网站服务器之间传递信息。 …

IIS 配置 HTTPS

前言 HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer 或 Hypertext Transfer Protocol Secure,超文本传输安全协议),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。使用SSL证书&…

群晖 Docker Gitlab 安装 及 https配置

群晖 Docker Gitlab 安装 及 https配置 安装 新建共享文件夹gitlab,创建下级目录/config /logs /data 修改权限完全控制 Docker下载镜像 配置存储位置及端口 启动容器 配置 https配置 在gitlab/config/目录下新建文件夹ssl将阿里云SSL证书文件放到ssl下&…

SpringBoot配置https

为什么要把网站转为https? https是网络数据传输协议,也就是说www的网站在传输数据的时候,都必须遵守这个协议,遵守统一的标准的协议,有利于数据更好的传送,而https则可以理解为是http的升级版或者安全版本…

nginx 代理 http、https 配置

nginx 代理 http、https 配置 http配置ssl https 配置 nginx 部署安装在之前的文章中已有教程,这里不再叙述,详情访问:nginx在centos7环境下安装本文主要讲述配置代理,包含http 、https代理,配置文件在 nginx 安装目录…

服务器https配置

1.登录阿里云后台: https://www.aliyun.com 在右上角"产品与服务"->“证书服务” 在证书列表,点击右上角"购买证书"->选择免费证书 返回证书列表, 选择刚刚申请的证书, 点击右边的"补全" 补全资料 等待审核通过之后下载配置证书 选…

Charles 抓包 Https 配置指南

一、说明 在做客户端开发的时候大家一定经常用到抓包工具去抓接口排查调试,非常的简捷方便。Charles 是一款非常好用的抓包工具,我在日常开发中也很喜欢用其进行接口联调、问题排查。 以前的客户端接口请求大多是 Http 传输的,抓接口直接配…

Charles抓https配置

环境:window10、charles4.6.1、ios14.4 1、第一步:pc安装证书 注意:证书存储的位置要选择‘受信任的根证书颁发机构’ 2、第二步:手机浏览器打开chls.pro/ssl下载安装证书 注意:下载安装完证书后,还需要如下设置 3、…

Tomcat配置Https

前言: 对于tomcat配置https还是挺简单的,首先你需要一个网站证书(里面包含了公钥和私钥),这个证书相当于钥匙,但是https证书是需要花钱买的,我们在练习模拟不需要花钱买,可以使用 j…

Tomcat详解(七)——Tomcat使用https配置实战

今天继续给大家介绍Linux运维相关知识,本文主要内容是Tomcat使用https配置实战。 一、tomcat证书配置 首先,要实现https,就必须先具有tomcat证书。我们在安装tomcat的时候,肯定都先安装了JAVA,而JAVA中有自带的证书生…

宝塔配置https

1. 2.左侧选中ssl,右上选中lets’encrypt 然后申请,结果如图 3.放行443 端口,我的是阿里云,其他云也是一样,要在安全组中出方向,添加开放443 4.宝塔中的设置,也要放行443端口的访问 5.然后用…

tomcat的https配置(亲测有效)

tomcat的https配置 1、下载证书2、配置证书1.上传文件到服务器2、编辑conf/server.xml文件 3、配置http自动跳转到https4、最后重启tomcat服务器5、测试 1、下载证书 申请域名并通过审核后就可以下载电子证书 点击选择我的证书 我这里选择免费证书 然后按照提示下载 tomcat 的…

nginx-http重定向到https配置

第一步打开服务器找到nginx目录文件,找到nginx.conf文件进行配置 我们只需要找到http所在的那个服务加入一行代码 return 301 https://www.abc.com$request_uri; 就可以将http协议改成https http{include mime.types;server{charset utf-8;listen 443 s…

Spring Boot 的HTTPS 配置

HTTPS 配置 由于HTTPS具有良好的安全性,在开发中得到了越来越广泛的应用,像微信公众号、小程序等的开发都要使用HTTPS来完成。对于个人开发者而言,一个HTTPS 证书的价格还是有点贵,国内有一些云服务器厂商提供免费的HTTPS证书&am…

https协议配置

前言:https协议配置,一般用于针对政府部门的终端有网络防火墙、网络过滤器等,使系统中的一些请求被拦截(劫持),原因一般为在请求头中有存在敏感信息,被网络过滤的监听器发现即拦截,可…

https配置

1.https定义: HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。它是一个URI scheme(抽象标识符体系),句法类同http:体…

配置HTTPS详细教程(内网)

前言 HTTPS (全称:Hyper Text Transfer Protocol over SecureSocket Layer),是以安全为目标的 HTTP 通道,在HTTP的基础上通过传输加密和身份认证保证了传输过程的安全性 。HTTPS 在HTTP 的基础下加入SSL,H…