• Nginx 反向代理https


    说明:

    1.nginx 1.2.0 centos 6.2
    2.这里所指的反向代理https是指nginx为ssl服务器,nginx与后端服务器的通信还是http,当然可能也可以实现nginx与后端服务器实现https通信,不过本文没有测试

    步骤:
    nginx要实现ssl,在编译时要添加--with-http_ssl_module,如:
    ./configure --with-http_ssl_module

    #cd /usr/local/nginx/conf
    #mkdir ssl
    #cd ssl
    生成一个私有key
    # openssl genrsa -des3 -out aoshiwei.com.key 1024
    提示输入密码
    生成CSR(Certificate Signing Request)文件:
    # openssl req -new -key aoshiwei.com.key -out aoshiwei.com.csr
    填写证书内容,组织机构、域名等,Common Name填写域名
     
    # cp aoshiwei.com.key aoshiwei.com.key.bak
    # openssl rsa -in aoshiwei.com.key.bak -out aoshiwei.com.key
    # openssl x509 -req -days 365 -in aoshiwei.com.csr -signkey aoshiwei.com.key -out aoshiwei.com.crt

    在nginx.conf中添加:
    [plain] view plaincopy
     
    1. server {  
    2.         ### server port and name ###  
    3.         listen          443 ssl;  
    4.         server_name     member.aoshiwei.com;  
    5.         ssl on;  
    6.    
    7.         ### SSL log files ###  
    8.         access_log      logs/ssl-access.log;  
    9.         error_log       logs/ssl-error.log;  
    10.    
    11.         ### SSL cert files ###  
    12.         ssl_certificate      ssl/aoshiwei.com.crt;  
    13.         ssl_certificate_key  ssl/aoshiwei.com.key;  
    14.         ### Add SSL specific settings here ###  
    15.         keepalive_timeout    60;  
    16.    
    17.         ###  Limiting Ciphers ########################  
    18.         # Uncomment as per your setup  
    19.         #ssl_ciphers HIGH:!ADH;  
    20.         #ssl_perfer_server_ciphers on;  
    21.         #ssl_protocols SSLv3;  
    22.         ##############################################  
    23.         ### We want full access to SSL via backend ###  
    24.         location / {  
    25.                 proxy_pass  http://member.aoshiwei.com;  
    26.                 ### force timeouts if one of backend is died ##  
    27.                 proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;  
    28.    
    29.                 ### Set headers ####  
    30.                 proxy_set_header Host $host;  
    31.                 proxy_set_header X-Real-IP $remote_addr;  
    32.                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    33.    
    34.                 ### Most PHP, Python, Rails, Java App can use this header ###  
    35.                 proxy_set_header X-Forwarded-Proto https;  
    36.    
    37.                 ### By default we don't want to redirect it ####  
    38.                 proxy_redirect     off;  
    39.                 }  
    40.       }  
  • 相关阅读:
    webpack 5 之持久化缓存
    前端资源加载失败优化
    如何用 JS 实现二叉堆
    简单解析一下扫码登陆原理,简单到你想不到!
    实战:Express 模拟 CSRF 攻击
    Yarn 的 Plug'n'Play 特性
    为什么现在我更推荐 pnpm 而不是 npm/yarn?
    小米3移动版刷安卓6.0-小米手机3 移动版 Flyme 6.7.11.24R beta
    小米5手机最后一版安卓6.0 MIUI8 6.11.10 小米5s手机最后一版安卓6.0 MIUI8 7.6.8
    vim格式转换
  • 原文地址:https://www.cnblogs.com/tonykan/p/3508083.html
Copyright © 2020-2023  润新知