Clay

用进废退 | 工字不出头

  • 主页
  • 归档
  • 随笔
  • 搜索
所有文章

Clay

用进废退 | 工字不出头

  • 主页
  • 归档
  • 随笔

Nginx配置Https

发表于:2019-03-19
字数统计:378
阅读量统计:

系统环境

1
2
CentOS Linux release 7.6.1810 (Core)
Linux 3.10.0-957.12.2.el7.x86_64 #1 SMP Tue May 14 21:24:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

系统安装 OpenSSL

1
2
3
4
5
# 更新系统
# yum update

# 安装openssl
# yum install openssl openssl-devel

Nginx 安装 SSL 模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 配置编译
# ./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_concat_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_upstream_consistent_hash_module

# 编译安装,会覆盖已安装的Nginx
# make && make install

Nginx 配置 SSL 证书与 SSL 性能调优

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server {
listen 443;
server_name www.example.cn;

# SSL证书
ssl on;
ssl_certificate /usr/local/nginx/cert/example.cn.crt;
ssl_certificate_key /usr/local/nginx/cert/example.cn.key;

# SSL性能调优
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;

...(省略)
}

Nginx 配置 Http 跳转 Https

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
# 第一种写法
server {
listen 80;
server_name www.example.cn;
rewrite ^(.*) https://$server_name$1 permanent;
}

# 第二种写法,将http的url通过301状态码重定向到https的url上
server {
listen 80;
server_name www.example.cn;
return 301 https://$server_name$request_uri;
}

server {
listen 443;
server_name www.example.cn;

# SSL性能调优
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;

...(省略)
}

Nginx 配置支持同时访问 80 和 443 端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
server {
listen 80 default backlog=2048;
listen 443 ssl;
server_name www.example.cn;

# SSL证书
# ssl on; # 注释掉
ssl_certificate /usr/local/nginx/cert/example.cn.crt;
ssl_certificate_key /usr/local/nginx/cert/example.cn.key;

# SSL性能调优
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;

...(省略)
}
本文作者: Clay
发布时间: 2019-03-19 19:45:43
最后更新: 2019-06-04 00:20:35
本文链接: https://www.techgrow.cn/posts/d65a2736.html
版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!
赏

谢谢你的支持

支付宝
微信
  • Web服务器

扫一扫,分享到微信

微信分享二维码
3D打印备忘录
Docker之十八镜像瘦身
© 2021 Clay
本站总访问量  人次
载入天数...载入时分秒...
粤ICP备19024664号
  • 所有文章

显示标签:

  • AI
  • C/C++
  • CI/CD
  • CentOS
  • Centos
  • Docker
  • HarmonyOS
  • Java
  • Linux
  • Manjaro
  • Python
  • Web服务器
  • 企业面试
  • 分布式
  • 前端
  • 区块链
  • 开发工具
  • 开源
  • 微服务
  • 数据库
  • 架构
  • 树莓派
  • 爬虫
  • 版本控制
  • 知识图谱
  • 算法与数据结构
  • 缓存
  • 网络攻防
  • 随笔

    [^_^] 出错啦!请重新刷新页面!