質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

6024閲覧

ALBのhttp->httpsのリダイレクト

madone99

総合スコア1855

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2017/06/06 03:06

編集2017/06/07 00:16

タイトルのことをしたく、ALBを下記リンクを参考にターゲットグループを作成し

from internet
[internet] http -> 80 [ALB] http -> 81 [nginx] (https redirect)
[internet] https -> 433 [ALB] http -> 80 [nginx] http -> any [WordPress]

from health-checker
[health-checker] http -> 80 [nginx] http -> any [WordPress]

のようにしたいのですが、ヘルスチェックでunhealthyになります。

http://qiita.com/spaceprobe/items/96550d3214f2930f8b1a

nginxの設定は以下になります。

fastcgi_pass unix:/var/run/php-fpm.sock; ```の箇所は、実際にそこに存在しているために変更しています。 何かご意見頂けますでしょうか?宜しくお願いします。 default.conf ---

server {
listen 81;
server_name example.com;
rewrite ^ https://$host$request_uri permanent;
}

server {
listen 80 http2;
listen [::]:80 http2;
server_name www.example.com;
return 301 http://example.com$request_uri;
}

server {
client_max_body_size 96M;
listen 80 http2;
listen [::]:80 http2;
root /var/www/html/wordpress;
server_name example.com;
charset utf-8;

add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains'; #resolver 8.8.4.4 8.8.8.8 valid=300s; resolver 127.0.0.1; resolver_timeout 10s; #return 301 https://$host$request_uri; # maintenance setting set $maintenance false; if (-e /var/tmp/maintenance.mode) { set $maintenance true; } if ($http_x_forwarded_for ~ ^(xxx.xxx.xxx.xxx|xxx.xxx.xxx.xxx)) { set $maintenance false; } #if ($maintenance = true) { # return 503; #} #error_page 503 @maintenance; #location @maintenance { # rewrite ^(.*)$ https://xxx.cloudfront.net break; #} location / { root /var/www/html/wordpress; index index.html index.htm index.php; try_files $uri $uri/ /index.php?q=$uri&$args @wp; if (!-e $request_filename) { rewrite ^.+?(/wp-.*) $1 last; rewrite ^.+?(/.*\.php)$ $1 last; rewrite ^ /index.php last; } } location ~* \.php$ { root /var/www/html/wordpress; try_files $uri @wp; fastcgi_pass unix:/var/run/php-fpm.sock; # fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*); fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress/$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_pass_header "X-Accel-Redirect"; fastcgi_pass_header "X-Accel-Expires"; fastcgi_read_timeout 180; include fastcgi_params; } location @wp { root /var/www/html/wordpress; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass unix:/var/run/php-fpm.sock; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress/index.php; include fastcgi_params; } # wp-config.phpへのアクセスを全て拒否 location ~* /wp-config.php { deny all; } location ~* /(phpmyadmin|myadmin|pma) { access_log off; log_not_found off; return 404; } location = /healthcheck.txt { #access_log off; return 204; break; } # error_page 404 /index.php?error=404; error_page 500 502 503 504 /50x.html; location /favicon { empty_gif; access_log off; log_not_found off; } location = /robots.txt { log_not_found off; access_log off; } location ~ /\. { deny all; log_not_found off; access_log off; } location ~* \.(pdf)$ { add_header X-Robots-Tag noindex; }

}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.example.com;
return 301 https://example.com$request_uri;
}

server {
client_max_body_size 96M;
listen 443 ssl default_server http2;
listen [::]:443 ssl http2;
server_name example.com;
root /var/www/html/wordpress;
charset utf-8;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem; ssl_dhparam /etc/nginx/ssl/dhparam.pem; keepalive_timeout 120; ssl_stapling on; ssl_stapling_verify on; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_session_timeout 10m; ssl_session_tickets off; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; ssl_prefer_server_ciphers on; add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains'; #resolver 8.8.4.4 8.8.8.8 valid=300s; resolver 10.0.0.2; resolver_timeout 10s; # maintenance setting set $maintenance false; if (-e /var/tmp/maintenance.mode) { set $maintenance true; } if ($http_x_forwarded_for ~ ^(xxx.xxx.xxx.xxx|xxx.xxx.xxx.xxx)) { set $maintenance false; } #if ($maintenance = true) { # return 503; #} #error_page 503 @maintenance; #location @maintenance { # rewrite ^(.*)$ https://xxx.cloudfront.net break; #} location / { root /var/www/html/wordpress; index index.html index.htm index.php; try_files $uri $uri/ /index.php?q=$uri&$args @wp; if (!-e $request_filename) { rewrite ^.+?(/wp-.*) $1 last; rewrite ^.+?(/.*\.php)$ $1 last; rewrite ^ /index.php last; } } location ~* \.php$ { root /var/www/html/wordpress; try_files $uri @wp; fastcgi_pass unix:/var/run/php-fpm.sock; # fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*); fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress/$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_pass_header "X-Accel-Redirect"; fastcgi_pass_header "X-Accel-Expires"; fastcgi_read_timeout 180; include fastcgi_params; } location @wp { root /var/www/html/wordpress; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress/index.php; include fastcgi_params; } # wp-config.phpへのアクセスを全て拒否 location ~* /wp-config.php { deny all; } location ~* /(phpmyadmin|myadmin|pma) { access_log off; log_not_found off; return 404; } location = /healthcheck.txt { #access_log off; return 204; break; } location ^~ /.well-known/acme-challenge { root /usr/local/letsencrypt; access_log /var/log/nginx/access_letsencrypt.log; error_log /var/log/nginx/error_letsencrypt.log; } # direcct access location = /.well-known/acme-challenge { return 404; } # error_page 404 /index.php?error=404; error_page 500 502 503 504 /50x.html; location /favicon { empty_gif; access_log off; log_not_found off; } location = /robots.txt { log_not_found off; access_log off; } location ~ /\. { deny all; log_not_found off; access_log off; } location ~* \.(pdf)$ { add_header X-Robots-Tag noindex; }

}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

TaichiYanagiya

2017/06/06 06:33

ヘルスチェックの設定は、プロトコル=HTTP、パス=/、成功コード=200 でしょうか? また、(1) ALB:443→Nginx:80 (2) ALB:443→Nginx:443 のどちらの構成でしょうか?
madone99

2017/06/06 06:38

ありがとうございます。追記いたしました。
guest

回答1

0

ベストアンサー

listen 80 側 server で、リダイレクトではなく、Wordpress やヘルスチェックを扱う設定が必要です。
現状では応答コードが 200 ではなく、301 が返っているので healthy にならないのだと思います。

また、location = /healthcheck.txt {} で 204 を返していますが、ヘルスチェックのパス=/healthcheck.txt、成功コード=204 となっているか確認ください。

投稿2017/06/06 07:03

TaichiYanagiya

総合スコア12146

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

madone99

2017/06/06 09:25

ご回答ありがとうございます。 なるほどです。考えたら80で受けているのでそちらでもWordPressの設定が必要ですよね。 ヘルスチェックの応答コードも成功コードを204に変更したのですが インスタンスを削除→追加してもunhealthyのままでした。
TaichiYanagiya

2017/06/06 11:40

一旦、/healthcheck.txt の "access_log off;" をコメントアウトして、アクセスログを確認するといいと思います。 User-Agent "ELB-HealthChecker/2.0" から "/healthcheck.txt" へのアクセスに "204" を返しているかどうか。
madone99

2017/06/06 22:39

ありがとうございます。 access.logを確認したら204を返すはずが302で返ってきておりました。 前掲のconfファイルを現在のものに変更したのですが、おかしな点ございますでしょうか?
TaichiYanagiya

2017/06/07 00:47

"302" を返すところは、@maintenance か 81番ポートのところくらいだと思います。 ヘルスチェックのポートが 81番ポートになっていませんでしょうか?
TaichiYanagiya

2017/06/07 01:01

すみません、81番ポートの rewrite は permanent なので "301" でした。 @maintenance が有効になっていませんでしょうか?
madone99

2017/06/07 01:08

メンテナンスとしてリダイレクトする設定を有効にしたのが原因のようでした。 アクセスログで204を返しているのですが、成功コードを204に指定してもunhealthyが変らないのは、どういう事が考えられますでしょう?
TaichiYanagiya

2017/06/07 01:13

デフォルトでは 30秒間隔で 5回成功(2分30秒)で healthy になるので、少し時間をおいて確認してみてください。
madone99

2017/06/07 21:15

試行錯誤してみたのですが、 [internet] https -> 433 [ALB] https -> 443 [nginx] の場合はヘルスチェックが成功するのですが、 [internet] https -> 433 [ALB] http -> 80 [nginx] [internet] http -> 80 [ALB] http -> 81 [nginx] [internet] http -> 80 [ALB] https -> 443 [nginx] はunhealthyから変化ありませんでした。 とりあえずは全経路をhttpsに構成変更しようと思います。 お忙しいところ、お付き合いいただきありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問