LoginSignup
1
0

More than 5 years have passed since last update.

AWSのAMIを使ってRStudioを構築する方法(2018.12)

Posted at

R Studio Server(WebUIでR言語が利用できる分析環境)を、
AWS(Amazon Web Service)のAMI(Amazon Machine Image)を利用してサクッと構築する。

HTTP版

以下のサイトでRSutido用のAMIが提供されています。

インスタンスを作成して、セキュリティグループの設定を行いましょう。
詳細な手順は省略します。

以下のURLでログインできればOKです。

  • http://〜インスタンスのIPv4〜/
  • Username: rstudio
  • Password: 〜インスタンスID〜

rstudio_demo_graphics.png

HTTPS化

イマドキHTTPS化は常識。Chromeからも警告されます。
http_security_alert.png

以下のようなネットワーク構成にします。

ブラウザ
| HTTPS(443)
ELB (ここに証明書を置く)
| HTTP(80)
Nginx
| TCP(8787)
R Studio

デフォルトの設定だとHTTPS経由でアクセスした際にlocalhost:8787にリダイレクトされてしまうので、Nginxの設定を書き換える。
Nginx再起動時の認証は「2.rstudio」を選択、パスワードはインスタンスID。

$ ssh ubuntu@54.95.161.241 -i ~/.ssh/id_rsa_rstudio.pem

$ sudo vi /etc/nginx/RStudioAMI/rstudio.conf

# 変更点は以下の通り。この記事のポイントはここね
@@ -1,9 +1,11 @@
 location / {
   proxy_pass http://localhost:8787;
-  proxy_redirect http://localhost:8787/ $scheme://$host/;
+  proxy_redirect http://localhost/ https://$host/;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection $connection_upgrade;
+  proxy_set_header Host $host;
+  proxy_set_header X-Forwarded-Proto https;
   proxy_read_timeout 20d;
   access_log /var/log/nginx/rstudio-access.log;
   error_log  /var/log/nginx/rstudio-error.log;

$ service nginx restart
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'nginx.service'.
Multiple identities can be used for authentication:
 1.  Ubuntu (ubuntu)
 2.  rstudio
Choose identity to authenticate as (1-2): 2
Password: 
==== AUTHENTICATION COMPLETE ===

ELBを構築する。プロトコルはHTTPS(443)。
証明書、ターゲットグループ、セキュリティグループは適当に。

ブラウザからhttps経由でアクセスできるようになっている事を確認して、
httpは遮断しておきましょう。

以上です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0