Nginx系列之使用ssl模块配置支持代理HTTPS链接

Nginx系列之使用ssl模块配置支持HTTPS访问

1、博客前言介绍

最近在用nginx代理https的第三方链接,因为不是做运维,所以对nginx并不是特殊熟悉,所以到处询问摸索了挺久

2、查看ssl_module

要使用nginx代理https的链接,先用检查nginx是否已经有安装了ssl module,如图使用命令:
cd /usr/local/nginx/sbin && ./nginx -V
在这里插入图片描述

3、安装openssl和openssl-devel

如果nginx没安装openssl,可以使用yum命令进行安装

yum -y install openssl openssl-devel

检查openssl是否安装成功

openssl version -a

4、创建服务器私钥

使用命令,回车之后,会让你输入密钥,reload nginx配置时候都要你验证这个PAM密码

openssl genrsa -des3 -out server.key 1024 

5、创建签名请求的证书

创建签名请求的证书(CSR),用于颁发公钥

openssl req -new -key server.key -out server.csr  

6、配置nginx reload不需要密码

1cp server.key server.key.org 2openssl rsa -in server.key.org -out server.key

7、标记证书使用上述私钥和CSR

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

8、修改nginx配置,支持SSL

1server { 2 listen 80; 3 listen 443 ssl; 4 server_name localhost; 5 6 #access_log logs/host.access.log main; 7 # 开启ssl 8 # ssl on; 9 #证书位置 10 ssl_certificate /usr/local/nginx/server.crt; 11 #私钥位置 12 ssl_certificate_key /usr/local/nginx/server.key; 13 ssl_session_timeout 5m; 14 #指定密码为openssl支持的格式 15 ssl_protocols SSLv2 SSLv3 TLSv1; 16 #密码加密方式 17 ssl_ciphers HIGH:!aNULL:xues!MD5; 18 #依赖SSLv3和TLSv1协议的服务器密码将优先于客户端密码 19 ssl_prefer_server_ciphers on; 20 21 // ... 省略 22}

注意点:

  • 要listen 443端口,https的端口是443,listen 443 ssl;
  • 要同时支持http和https链接代理,要注释ssl on;
  • ssl_certificatessl_certificate_key,这两个参数需要根据证书位置配置

配置location代理转发:

1location /portal{ 2 proxy_pass https://127.0.0.1:8888/portal; 3 proxy_set_header Host $host; 4 proxy_set_header X-Real-IP $remote_addr; #获取真实ip 5 proxy_connect_timeout 90; 6 proxy_send_timeout 90; 7 proxy_read_timeout 90; 8 proxy_buffer_size 4k; 9 proxy_buffers 4 32k; 10 proxy_busy_buffers_size 64k; 11 proxy_temp_file_write_size 64k; 12 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#获取代理者的真实ip 13 proxy_redirect off; 14 }

本文同步分享在 博客“smileNicky”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

Nginx配置https

一、开启nginx的ssl模块1.未安装过nginx,编译安装配置参数如下:./configure\prefix/usr/local/nginx\withpcre\withhttp\_ssl\_modulessl模块\withhttp\_stub\_status\_module\wit