• Nginx同时支持Http和Https的配置


    现在的网站支持Https几乎是标配功能,Nginx能很好的支持Https功能。下面列举一个配置同时支持Http和Https的功能。

    需要注意的是:既然选择使用Https,就是为了保证通信安全,那么就没必要再用Http进行通信了。在URL中还支持Http的方式,主要是为了用户不知道网站支持Https,还是使用Http的方式进行访问。这时Nginx后台需要自动将Http请求转成Https的方式,这样就又能支持Http,又能保证通信安全了。

    废话不多说,下面直接贴一个Nginx支持Http和Https的配置,是我的wordpres网站支持Https的配置,大家何以参考。

    
    server
    {
        # 开启Https
        listen 443 ssl;
        # 配置证书,免费证书怎么申请这边就不多说了。在晚上搜索腾讯云或者阿里云免费证书申请即可
        ssl_certificate /etc/nginx/conf.d/cert/4351595_www.xxx.pem;
        ssl_certificate_key /etc/nginx/conf.d/cert/4351595_www.xxx.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;
        
        server_name xxx;
        index index.html index.htm index.php;
        root  /data/wwwroot/wordpress;
        error_log /var/log/nginx/wordpress-error.log crit;
        access_log  /var/log/nginx/wordpress-access.log;
    
        # 这边用于包含其他配置
        include extra/*.conf;
        include conf.d/rewrite/wordpress.conf;
    
    }
    
    # 将Http请求转化成Https请求
    server {
        listen 80;
        server_name xxx;
        rewrite ^/(.*) https://$server_name$request_uri? permanent;
    }
    
    
  • 相关阅读:
    android 瀑布流的实现详解,附源码
    NodeJs新手学习笔记之工具准备
    android app的类响应式设计
    开源一个友盟 for android 操作的封装包
    谈谈多门程序语言的学习策略之一
    谈谈android 布局 的优化
    android 滑动指引页的设计
    彻底弄懂CSS盒子模式
    关于内容管理系统IWMS的几个问题
    数码相机常用英文缩写对照表
  • 原文地址:https://www.cnblogs.com/54chensongxia/p/13518330.html
Copyright © 2020-2023  润新知