2016-09-05 13 views
0

Nginxを実行しているserver1がserver2に "/ api"とその他いくつかのものを保持しながら、すべての "/"位置をserver2に転送する状況が発生しました。これはSSLの機能を維持しようとしています。 WP URLをhttp://test.example.comからhttps://example.comに移動しようとすると正面ページの読み込みが正しく行われますが、読み込みwp-adminはリダイレクトが多すぎます。nginx上流のワードプレス定数リダイレクト

Server1にNginxは:

 
upstream webapp_url { 
    server IP:80; 
} 

server { 
     listen 443 ssl; 
     server_name www.example.com example.com; 
     access_log /var/log/nginx/example.log; 

     ssl_certificate /etc/nginx/ssl/example.crt; 
     ssl_certificate_key /etc/nginx/ssl/server.key; 
     ssl_ciphers RC4:HIGH:!aNULL:!MD5; 
     ssl_prefer_server_ciphers on; 

     location /files/ { 
       root /home; 
       access_log off; 
       expires max; 
       if ($request_filename !~* ^.*?\.(jpg)|(png)|(gif)|(pdf)){ 
         add_header Content-Disposition: "$request_filename"; 
       } 
     } 

     location/{ 
       # proxy_pass http://site_url/; 
       proxy_http_version 1.1; 
       proxy_set_header Upgrade $http_upgrade; 
       proxy_set_header Connection 'upgrade'; 
       proxy_set_header Host $host; 
       proxy_set_header X-Forwarded-For $remote_addr; 
       proxy_set_header X-Forwarded-Proto https; 
       proxy_cache_bypass $http_upgrade; 
       proxy_set_header X-Example "1"; 
       proxy_pass http://webapp_url/; 
     } 

これは、他のサーバーの罰金、ホームページをロードし、(私は管理者にそれを変更することができませんでしだから、混合コンテンツの警告が)すべての作業をリンクします。 WP siteurlおよびhomeは両方とも新しいアドレスに設定されます。

Server2のNginxは:

 
server { 
    #listen  443 ssl; 
    listen 80; 
    server_name example.com test.example.com; 
    client_max_body_size 30M; 
    error_log /var/log/wordpress/error.log info; 
    location/{ 
     root /home/wordpress; 
     try_files $uri $uri/ /index.php?q=$request_uri; 
     index index.php index.html index.htm; 
    } 

    #ssl_certificate /etc/nginx/ssl/example.crt; 
    #ssl_certificate_key /etc/nginx/ssl/example.key; 
    #ssl_ciphers RC4:HIGH:!aNULL:!MD5; 
    #ssl_prefer_server_ciphers on; 

    error_page 404    /404.html; 
    location = /404.html { 
     root /usr/share/nginx/html; 
    } 

    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /usr/share/nginx/html; 
    } 

    # 
    location ~ \.php$ { 
     root   /home/wordpress; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
    } 
} 

ロード/wp-admin/は(同じURLへの)無限のリダイレクトを開始します。私もwp-config.phpでそれを定義した:接続が安全であるかどうかを確認するために

 
define('WP_HOME','https://example.com'); 
define('WP_SITEURL','https://example.com'); 

答えて

0

wp-adminチェックを、それ以外の場合は、同じURLのhttpsバージョンにリダイレクトします。あなたのような状況では、リダイレクトループが発生します。

WordPressに接続が安全であることを伝える必要があります。

私はあなたと、サーバ1上の適切なヘッダーを設定することに注意してください:(あなたのケースでは、$schemeの値は、ハードワイヤードhttpsにある)

proxy_set_header X-Forwarded-Proto $scheme; 

しかし、HTTPSパラメータの形式でこれをWordPressに渡して、値をonにする必要があります。

これは、(サーバー2上)mapディレクティブで実現されます。

map $http_x_forwarded_proto $https_flag { 
    default off; 
    https on; 
} 
server { 
    ... 
} 

mapディレクティブはhttpブロック内に配置された上記のようにあなただけのserverブロックの上に置くことができthis documentを参照してください。また

)詳細については、()サーバー2上のWordPressへHTTPSパラメータを渡すために別のfastcgi_paramを追加します。

location ~ \.php$ { 
    ... 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param HTTPS $https_flag; 
    ... 
} 
関連する問題