Linux搭建nginx实现https转发

本文借鉴:阿里云-SSL数字证书Nginx配置部署指导

1.域名 例如:www.aa.com

    设置解析地址:指向公网地址 116.116.116.116

2.具有公网环境的linux服务器   例如:116.116.116.116

3.服务器安装nginx,不会的自行学习

4.购买或者去免费的网站生成ssl证书 ,这里推荐一个免费生成ssl证书的网站>freessl.org

5.在网站下载生成的证书(一个压缩包,包含两个文件*.pem, *.key)

6.在nginx的 nginx.conf同级目录创建文件夹 cert ,(/usr/local/nginx/conf/cert),并把压缩包中的两个文件上传到cert文件中,或者直接放到nginx.conf 同级目录下

7.修改nginx.conf配置文件:

server
    {
        listen 80;
        #listen [::]:80 default_server ipv6only=on;
        server_name www.aa.com;#域名地址
        location /test {
                proxy_pass http://127.0.0.1:8080/index.html;  #转发后访问的地址
            }

}

#以下是ssl配置

server {
    listen 443;
    server_name www.aa.com;
    ssl on;
    root html;
    index index.html index.htm;
    ssl_certificate   cert/123456789.pem; #证书
    ssl_certificate_key  cert/123456789.key;#证书
    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 /test {
        proxy_pass http://127.0.0.1:8080/index.html;#转发后访问的地址
    }
}

8.通过浏览器https://www.aa.com/test

注意:注意443端口占用情况 lsof -i:443,如不是nginx占用443端口,kill pid 杀死

重新启动nginx服务 :service nginx reload

[root@localhost bodhi-app-2802-5221]# lsof -i:443
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
nginx   11817 root   11u  IPv4 13925764      0t0  TCP *:https (LISTEN)
nginx   11818  www   11u  IPv4 13925764      0t0  TCP *:https (LISTEN)
 

你可能感兴趣的:(Linux)