`
wbj0110
  • 浏览: 1536685 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

RStudio Server: Running with a Proxy

阅读更多

Overview

If you are running RStudio on a public network it is strongly recommended that you deploy RStudio behind another web server (e.g. Nginx or Apache) which acts as a reverse proxy to it. Doing this allows you to benefit from the the robust HTTP protocol handling built into the web server. This has both performance (e.g. keep-alive) and security (e.g. rejection of maliciously malformed requests) benefits.

Nginx Configuration

On Debian or Ubuntu a version of Nginx that supports reverse-proxying can be installed using the following command:

sudo apt-get install nginx

To enable an instance of Nginx running on the same server to act as a front-end proxy to RStudio you would add commands like the following to your nginx.conf file:

http {
  server {
    listen 80;
    
    location / {
      proxy_pass http://localhost:8787;
      proxy_redirect http://localhost:8787/ $scheme://$host/;
    }
  }
}

If you want to serve RStudio from a custom path (e.g. /rstudio) you would edit your nginx.conf file as shown below:

location /rstudio/ {
  rewrite ^/rstudio/(.*)$ /$1 break;
  proxy_pass http://localhost:8787;
  proxy_redirect http://localhost:8787/ $scheme://$host/rstudio/;
}

After adding these entries you'll then need to restart Nginx so that the proxy settings take effect:

sudo /etc/init.d/nginx restart

Apache Configuration

To enable an instance of Apache running on the same server to act as a front-end proxy to RStudio you need to use the mod_proxy. The steps for enabling this module vary across operating systems so you should consult your distribution's Apache documentation for details.

On Debian and Ubuntu systems Apache can be installed with mod_proxy using the following commands:

sudo apt-get install apache2
sudo apt-get install libapache2-mod-proxy-html
sudo apt-get install libxml2-dev

Then, to update the Apache configuration files to activate mod_proxy you execute the following commands:

sudo a2enmod proxy
sudo a2enmod proxy_http

Once you have enabled mod_proxy in your Apache installation you need to add the required proxy commands to your VirtualHost definition. For example:

<VirtualHost *:80>

  <Proxy *>
    Allow from localhost
  </Proxy>

  ProxyPass        / http://localhost:8787/
  ProxyPassReverse / http://localhost:8787/

</VirtualHost>

Note that if you want to serve RStudio from a custom path (e.g. /rstudio) you would replace the ProxyPass directives described above to:

ProxyPass        /rstudio/ http://localhost:8787/
ProxyPassReverse /rstudio/ http://localhost:8787/
RedirectMatch permanent ^/rstudio$ /rstudio/

Finally, after you've completed all of the above steps you'll then need to restart Apache so that the proxy settings take effect:

sudo /etc/init.d/apache2 restart

RStudio Configuration

Once you are successfully proxying requests from Nginx or Apache to RStudio you should change the port RStudio listens on from 0.0.0.0 (all remote clients) to 127.0.0.1 (only the localhost). This ensures that the only way to connect to RStudio is through the proxy server. You can do this by adding the www-address entry to the /etc/rstudio/rserver.conf file as follows:

www-address=127.0.0.1

Note that this config file does not exist by default so you may need to create it if it doesn't already exist.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics