启动一个使用 Ubuntu 作为操作系统的 AWS 实例,以及一个安全组,除了通过端口 22 的 SSH 连接之外,该安全组还具有端口 443 上的 HTTPS 入站连接。您的实例还必须具有公共 DNS。
机器启动并运行后,使用 SSH 登录。
使用提供的说明安装 RStudio 服务器here https://www.rstudio.com/products/rstudio/download-server/,通过执行:
sudo apt-get update
sudo apt-get install r-base
sudo apt-get install gdebi-core
wget https://download2.rstudio.org/rstudio-server-1.1.463-amd64.deb
sudo gdebi rstudio-server-1.1.463-amd64.deb
注:具体名称.deb
文件将随着 RStudio 服务器的新版本而更改。
我们将按照提供的说明进行操作here https://www.linode.com/docs/development/r/how-to-deploy-rstudio-server-using-an-nginx-reverse-proxy/ and here https://www.digitalocean.com/community/tutorials/how-to-create-an-ssl-certificate-on-nginx-for-ubuntu-14-04将 nginx Web 服务器配置为反向代理 https://en.wikipedia.org/wiki/Reverse_proxyRStudio 服务器连接到 Web 浏览器并使用 SSL。要安装 nginx,请执行:
sudo apt-get install nginx
创建 SSL 证书:
sudo mkdir /etc/nginx/ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
后一个命令创建两个文件:密钥文件和 SSL 证书文件。
下创建一个文件/etc/nginx/conf.d/rstudio.conf
并编辑它(注意:您需要使用sudo nano /etc/nginx/conf.d/rstudio.conf
或类似)添加:
server {
listen 80;
listen [::]:80;
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
server_name ec2-11-22-333-444.us-west-2.compute.amazonaws.com;
location / {
proxy_pass http://localhost:8787/;
proxy_redirect http://localhost:8787/ $scheme://$host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
}
}
在哪里更换server_name
字段包含您的 AWS 实例的公共 DNS IP。
此外,您还需要编辑/etc/nginx/nginx.conf
文件中添加以下行到http
block:
http {
# All you other settings up here...
server_names_hash_bucket_size 128;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
}
的设置server_names_hash_bucket_size
128 很重要,原因如下here https://gist.github.com/muhammadghazali/6c2b8c80d5528e3118613746e0041263
最后编辑你的/etc/rstudio/rserver.conf
配置文件中添加以下行:
www-address=127.0.0.1
接下来为您的用户创建用户帐户。例如:
sudo adduser arokem
您现在应该能够重新启动 nginx 和 rstudio-server:
sudo rstudio-server restart
sudo systemctl restart nginx
并将您的浏览器定向到https://ec2-11-22-333-444.us-west-2.compute.amazonaws.com
。您可能会从浏览器收到一条警告,指出它无法识别您的 SSL 证书。可以安全地忽略此警告(在本例中),然后继续进入 RStudio 服务器登录窗口。使用您刚刚创建的用户登录名来访问 RStudio。