Cloudflare下如何让WordPress支持HTTPS(配置SSL)

Cloudflare无疑是全球CDN加速较为可靠的方案。使用Cloudflare后,那WordPress配置HTTPS应该怎么配置呢?

Cloudflare设置

概述:在Cloudflare的“SSL/TLS概述”中需要设置“完全 - 端到端加密,使用服务器上的自签名证书”模式。

客户端证书:在“SSL/TLS客户端证书”需要创建客户端证书。创建后需要保存“.pem”、“.key”两个文件,需要配置到ngnx。

边缘证书:在“SSL/TLS边缘证书”的“自动 HTTPS 重写”需要开启,否则后台编辑器、CSS样式等资源会由于跨域问题无法访问。

配置nginx虚拟主机

server {
    listen       80;
    server_name  wpmore.cn;
    index index.php index.html;
    root /var/www/html/wpmore.cn;

    #charset koi8-r;

    access_log  /var/log/nginx/wpmore.cn.access.log  main;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass   php-fpm;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

# HTTPS server
#
server {
    listen       443 ssl;
    server_name  wpmore.cn;
    index index.php index.html;
    root /var/www/html/wpmore.cn;

    ssl_certificate      /etc/nginx/ssl/wpmore.cn.pem;
    ssl_certificate_key  /etc/nginx/ssl/wpmore.cn.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass   php-fpm;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

配置好nginx后,reload或者restart nginx。

安装WordPress

访问你的WordPress应用程序网址,继续安装即可。

分类 WordPress技巧 本文由 清白之年 原创发布,转载请注明文章来源。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注