タイトルの通りですが、色々と調べながら進めているものの、解決に至らず知見をお貸しいただけますでしょうか。
=====================
さくらVPS・CentOS7
バック:Apache 2.4.6
フロント:nginx 1.13.12
WordPress:4.9.5
=====================
【やりたいこと】
Apacheのバーチャルホストと、リバースプロキシサーバーにnginxを使い、同一IPアドレスで複数の常時SSLサイトを運用する
=====================
【問題】
URLにアクセスすると、両サイトとも301のリダイレクトループが発生しサイトが表示できない
=====================
【やったこと】
1.各種サーバー設定及びバーチャルホストを下記の通り指定
(/etc/nginx/conf.d/reverse_proxy.conf)
server { listen 80; server_name example_1.com; return 301 https://example_1.com$request_uri; } server { listen 80; server_name example_2.com; return 301 https://example_2.com$request_uri; } server { listen 443 ssl; server_name example_1.com; ssl on; ssl_certificate /etc/letsencrypt/live/example_1.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example_1.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSV1.2; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; client_max_body_size 20M; location / { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; proxy_redirect off; } } server { listen 443 ssl; server_name example_2.com; ssl on; ssl_certificate /etc/letsencrypt/live/example_2.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example_2.com]/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSV1.2; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; client_max_body_size 20M; location / { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; proxy_redirect off; } }
(/etc/httpd/conf/httpd.conf)
Listen 8080 ServerName localhost:8080
(/etc/httpd/conf.d/ssl.conf)
Listen 8443 https <VirtualHost _default_:8443>
(/etc/httpd/conf.d/vhost.conf)
<VirtualHost *:8080>
(/etc/httpd/conf.d/vhost-le-ssl.conf)
<VirtualHost *:8443>
2.Apacheとnginxを再起動
3.WordPressの設定ファイルに下記の指定
(wp-config.php)
<?php define('FORCE_SSL_ADMIN', true); if ( ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) { $_SERVER['HTTPS']='on'; } $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
(functions.php)
<?php remove_action('template_redirect', 'redirect_canonical');
=====================
【補足】
・バックエンドApache側のhttpポート番号は8080に変更
・バックエンドApache側のhttpsポート番号は8443に変更
・ssl証明書はLet's Encryptを使用
・Apacheのバーチャルホストでhttp→httpsのリダイレクトを指定
・現在はApacheのみで問題なく運用できています
・実際の環境では「example_1.com」「example_2.com」の部分にそれぞれ実存するドメインが入ります
=====================
あまり理解できていないところもあり、とりあえずネット上にある情報を手当たり次第に試している状況で、、
原因を調べる上で、何か良いアプローチなどもあれば教えていただけますと幸いです。
どうぞ宜しくお願い致します。
回答1件