nginx 支持https请求

一、获取安装包
https://www.openssl.org/source/openssl-1.0.2e.tar.gz  (openssl的版本必须在1.0.2e及以上)
http://nginx.org/download/nginx-1.10.3.tar.gz    (nginx的版本必须在1.9.5以上)
二、解压三个包到相同目录编译nginx
./configure --prefix=/etc/nginx --with-openssl=../openssl-1.0.2e --with-pcre --with-zlib=../zlib-1.2.11 --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
三、配置运行
注意:如果机器没有安装 openssl 先安装 yum -y install openssl (openssl version 看版本)
配置nginx伪证书、配置文件中开启https即可
步骤1: 到需要放置证书的目录(选在nginx的conf目录下就可以),建立服务器的私钥(此过程需输入密码短语)
openssl genrsa -des3 - out server.key 1024
步骤2: 创建证书签名请求csr
openssl req - new -key server.key - out server.csr
步骤3:对于使用上面私钥启动具有ssl功能的nginx,有必要移除输出的密码
cp server.key server.key.orgopenssl rsa - in server.key.org - out server.key
步骤4: 使用上面的私钥和CSR对证书进行签名
openssl x509 -req -days 365 - in server.csr -signkey server.key - out server.crt
步骤5:配置nginx
upstream test_01 {
server 192.168.45.15:8080;
}
upstream test_02 {
server 192.168.45.15:8090;
}
server {
listen 443 http2 ssl;
server_name sw.test.boot01;

ssl_certificate server1.crt;
ssl_certificate_key server1.key;
location /test01 {
root html;
index index.html index.htm;
proxy_pass http://test_01;
}
}
server {
listen 443 http2 ssl;
server_name sw.test.boot02;

ssl_certificate server2.crt;
ssl_certificate_key server2.key;
location /test02 {
root html;
index index.html index.htm;
proxy_pass http://test_02;
}
}
步骤6:启动nginx并用谷歌浏览器访问

chrome://net-internals/#http21chrome://net-internals/#http2


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值