dougang6178 2017-08-01 23:36
浏览 105

当WP或WP内的插件强制SSL时,使用NGINX和WordPress进行无限重定向循环

I am running into an issue when trying to enforce SSL on Wordpress whether it be by changing the site URL to HTTPS or setting force-wpadmin or using the force ssl on shopping cart from WooCommerce. If you type in https:// it works fine but when it's forced from WordPress that page get stuck in an infinite loop.

The site is also behind a Full (Strict) CloudFlare w/ SSL enabled.

The server is running NGINX with PHP-FPM (PHP7) and the latest version of WordPress. I am using NGINX Caching along with OPCache. I have a feeling it may have to do with my nginx.conf file but i'm not sure. Please see below.

user  username;
worker_processes 2 ;

pid        /var/run/nginx.pid;

events {
    worker_connections  2048;
    multi_accept on;
    use epoll;
}

worker_rlimit_nofile 4096;

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 60;
    types_hash_max_size 2018;
    client_max_body_size 124m;
    client_body_buffer_size 1m; 
    client_body_timeout 47; 
    client_header_timeout 47;


    # server_tokens off;

    server_names_hash_bucket_size 128;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    open_file_cache max=2000 inactive=20s; 
    open_file_cache_valid 60s; 
    open_file_cache_min_uses 5; 
    open_file_cache_errors off;

    fastcgi_buffers 256 16k; 
    fastcgi_buffer_size 128k; 
    fastcgi_connect_timeout 3s; 
    fastcgi_send_timeout 120s; 
    fastcgi_read_timeout 120s; 
    fastcgi_busy_buffers_size 256k; 
    fastcgi_temp_file_write_size 256k; 
    reset_timedout_connection on; 

    ##
    # SSL Settings       
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    # Gzip Settings
    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 2;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon image/webp application/json application/vnd.ms-access application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel; 

# Nginx Fast Cache Settings
fastcgi_cache_path /dev/shm/nginx-cache levels=1:2 keys_zone=WORDPRESS:1024m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

# HTTP Server
    server {
        listen 80 default_server;
    listen 443 ssl;
        #listen [::]:80 default_server;
    server_name www.siteurl.com;

    ssl_certificate /efs/ssl/name.crt;
    ssl_certificate_key /efs/ssl/name.key;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log warn;

        root /efs/public_html1/;

    include /efs/name/nginx.conf;

    index index.php;

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

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

    #Set static file browser caching
        location ~* \.(css|js)$ {
                expires 30d;
                log_not_found off;
                access_log off; 
    }

        location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
                expires 60d;
                log_not_found off;
                access_log off;
        }

    #Prevent access to hidden files
    location ~ /\. {
        access_log off;
        log_not_found off; 
        deny all;
    }

    #Cache Settings
    set $skip_cache 0;

    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
        set $skip_cache 1;
    }   
    if ($query_string != "") {
        set $skip_cache 1;
    }   

    # Don't cache uris containing the following segments
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
        set $skip_cache 1;
    }   

    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
        set $skip_cache 1;
    }

        location / {
                try_files $uri $uri/ /index.php$is_args$args;

    }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php-fpm-7.0.sock;
                fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
                include fastcgi_params;

        fastcgi_cache_bypass $skip_cache;
            fastcgi_no_cache $skip_cache;

        fastcgi_cache WORDPRESS;
        fastcgi_cache_valid 60m;
        }

    location ~ /purge(/.*) {
        fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
    }

    add_header X-Cache-Status $upstream_cache_status;   
}

}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?