redashというよりnginxの設定の話です
構成
- https://redash.io/help/open-source/setup に載っているAMIを使ってセットアップしたRedash (Ubuntu 16.04)
- Elastic Load Balancer経由でバックエンドの80番ポートに接続、ELB側は443のみ許可
- ACMで取得したSSL証明書をELBにインストール
起きていた問題
-
https://redash.example.com
に接続しようとすると、http://redash.example.com?next=http://redash.example.com/login
にリダイレクトされてしまった
やったこと
-
/etc/nginx/site-available/redash
を変更
upstream rd_servers {
server 127.0.0.1:5000;
}
server {
server_tokens off;
listen 80 default;
server_name redash.example.com;
if ($http_x_forwarded_proto = 'http') {
return 301 https://$server_name$request_uri;
}
access_log /var/log/nginx/rd.access.log;
gzip on;
gzip_types *;
gzip_proxied any;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_pass http://rd_servers;
}
}
- redashを再起動
$ sudo nginx -s reload
主にやったこと
server_name redash.example.com;
if ($http_x_forwarded_proto = 'http') {
return 301 https://$server_name$request_uri;
}
-
proxy_set_header
の値を変更- $schemeのままだと常に
http
が入ってしまっているので、$http_x_forwarded_protoを使うことでELBから転送された元のプロトコル(https
)をセットするようにする。
- $schemeのままだと常に
- proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;