Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我
所有文章 外链

Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我

配置ssl证书

阅读数:次 2019-09-04
字数统计: 535字   |   阅读时长≈ 2分

前提

443 端口 已经开放。

防火墙放行 443 端口。

证书安装

对应厂商购买后,下载证书。此步骤见厂商文档。

nginx 配置

完整配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
upstream publicCluster {
ip_hash; # one user visit one ip
server 192.168.100.1:8092;
server 192.168.100.2:8092;
}

server {
# 同时支持http和https
listen 80;
listen 443 ssl;
server_name test.com.cn public.test.com.cn;

#root html;
#index index.html index.htm;

ssl_certificate cert/test.com.cn.pem;
ssl_certificate_key cert/test.com.cn.key;

ssl_session_cache shared:SSL:1m;
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;

location / {
proxy_pass http://publicCluster/;
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 X-Forwarded-Proto $scheme;
proxy_connect_timeout 60000;
proxy_read_timeout 60000;
proxy_send_timeout 60000;
}

#location ~ .*\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt|mp4|ttf|mov|html|avi|wmv)$ {
# proxy_pass http://publicCluster;
#}

# statics
location ~ ^/(commons|images|plugin|scripts|styles)/ {
root /mnt/test/statics/public;
access_log off;
#expires 30d;
}

location ^~ /upload/ {
root /mnt/test/;
}
}

tomcat

配置如下,其中proxyPort="443"和Valve配置重点。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<Service name="Catalina">
...
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443"
proxyPort="443"/>

<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="x-forwarded-for"
remoteIpProxiesHeader="x-forwarded-by"
protocolHeader="x-forwarded-proto"
/>

<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!--关键-->
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="x-forwarded-for"
remoteIpProxiesHeader="x-forwarded-by"
protocolHeader="x-forwarded-proto"
protocolHeaderHttpsValue="https"/>
<Context path="" docBase="/oschina/webapp" reloadable="false"/>
</Host>
</Engine>
</Service>

代码层面

因ssl传输会消耗多余的带宽,影响性能,所以对于一些安全性要求不高的数据传输,可直接用http传输。所以在代码层面,可以看情况而定使用http或https。

注意 ctx 的配置,以及system.properties配置文件中,http链接不要写死,可以在ResourceUtil.java中动态判断

1
2
3
4
5
6
7
8
public static String getCameraPicUrl(HttpServletRequest request) {
int serverPort_ = request.getServerPort();
if (serverPort_ == 443) {
return "https://" +bundle.getString("PicUrl");
} else {
return "http://" +bundle.getString("PicUrl");
}
}

参考

  • 常用的Nginx配置(https,集群)
  • nginx.org/configuring_https_servers
  • 本文作者: Linking
  • 本文链接: https://linking.fun/2019/09/04/配置ssl证书/
  • 版权声明: 版权所有,转载请注明出处!
  • ssl
  • CS

扫一扫,分享到微信

Linux下Oracle数据库基本操作
Nginx常见问题记录
  1. 1. 前提
  2. 2. 证书安装
  3. 3. nginx 配置
  4. 4. tomcat
  5. 5. 代码层面
  6. 6. 参考
© 2015-2026 Linking
GitHub:hexo-theme-yilia-plus by Litten
本站总访问量次 | 本站访客数人
  • 所有文章
  • 外链

tag:

  • weather
  • 需求
  • essay
  • basketball
  • olympic
  • nginx
  • APPScan
  • SQl盲注
  • xss
  • Ajax
  • ajax
  • ai
  • agent
  • openclaw
  • ccf
  • Nginx
  • HTML5
  • html5
  • hmtl5
  • sse
  • JavaScriptCore
  • Oracle
  • operation
  • Linux
  • deploy
  • Mac Office
  • markdown
  • ListView
  • GridView
  • MySQL
  • 慢查询
  • mongodb
  • 转置
  • thought
  • network
  • ubuntu
  • NetworkManager
  • RFKill
  • Netplan
  • avatar
  • cocoa
  • blog
  • Gitalk
  • container
  • macvlan
  • docker
  • oracle
  • cookie
  • patch
  • gitea
  • git
  • iOS
  • https
  • 多线程
  • bundle
  • 兼容性
  • HTTP
  • 绘图
  • cs
  • java
  • 效率
  • 快捷键
  • route
  • nodejs
  • pip
  • arcgis
  • arcgis 建模
  • 标识
  • redis
  • read
  • bookList
  • running
  • showdoc
  • disk
  • unit-test
  • D.Wade
  • thoughts
  • duoduo
  • Python
  • python
  • tomcat
  • 读书节
  • session
  • jdk
  • war
  • 加班
  • Android onclick事件监听
  • 正则
  • 手机品牌匹配
  • ntp
  • OpenLayers
  • Geoserver
  • wechat
  • 微信公众号
  • 爬虫
  • WeChat
  • 张靓颖
  • 动漫
  • vpn
  • PPT
  • MarkDown
  • plan
  • 朱赟
  • 极客时间专栏
  • 极客邦
  • 模块化
  • MVC
  • excel
  • NBA
  • kobe
  • team
  • crawler
  • 进度条
  • ssl
  • book
  • anti-stealing-link
  • Agentic Engineering
  • Vibe Coding
  • Software 3.0
  • Andrej Karpathy
  • LLM
  • Programming

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia-plus根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • GitHub Trending
  • OpenAI ChatGPT
  • Gitee码云
  • 简书
  • CSDN