Reverse proxy in Rstudio Connect configuration

Hello,

I'm trying to set up the Rstudio Connect and right now do the reverse proxy trough nginx.

In this post: https://docs.rstudio.com/connect/admin/running-a-proxy.html#nginx-as-reverse-proxy
there are some examples for the configuration file but they don't tell where those editions needs to happen and so i don't know if the edition should be made in

/etc/nginx/nginx.conf

or

/etc/nginx/sites-enabled/default

The second one i took from this guide: https://deanattali.com/2015/05/09/setup-rstudio-shiny-server-digital-ocean/#install-r
which is a guide for install Shiny Server and not RStudio Connect.

I tried to both suggestions of edition in /etc/nginx/sites-enabled/default file, but did not work.

Can anyone please clarify this for me?

Thanks in advance.

Can you show your /etc/nginx/sites-enabled/default file?

Hello andresrcs,

Of course. I don't know to copy text from the ubuntu terminal (i tried ctrl+shift+c but did not work), so i will put the print screens in sequence.


Everything below that is in comment.

Screenshots are not very useful, typically on a Linux terminal, text gets copied just by selecting it.
Also, you have made no changes to the file, can you show what you have tried that is not working?

Ah, there it is, thank you.

Yes, i deleted the changes to start from the beggining.

First try was to put this block of code in "/etc/nginx/sites-enabled/default" file:

http {
  map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
  }
  server {
    listen 80;

    client_max_body_size 0; # Disables checking of client request body size

    location /rsconnect/ {
      rewrite ^/rsconnect/(.*)$ /$1 break;
      proxy_set_header X-RSC-Request $scheme://$host:$server_port$request_uri;
      proxy_pass http://MyIP_adress:3939;
      proxy_redirect / /rsconnect/;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_http_version 1.1;
    }
  }
}

Did not work.
Second, i tried to put this same block of code in "/etc/nginx/nginx.conf" file.
Also did not work.

The third try was put this next block of code in "/etc/nginx/sites-enabled/default", first part before the server{...} and the other part right after the server_name _; as described in Dean Attali tutorial.

map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}
location /rsconnect/ {
  proxy_pass http://MyIP_adress:3939/;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection $connection_upgrade;
  rewrite ^(/rsconnect/[^/]+)$ $1/ permanent;
}

I'm assuing this is just illustrative and you have used some IP, it was your public IP or local IP? can you try using localhost instead?, try with this

map $http_upgrade $connection_upgrade {
      default upgrade;
      ''      close;
    }

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm;

        server_name _;

        client_max_body_size 0; # Disables checking of client request body size

    	location /rsconnect/ {
      		rewrite ^/rsconnect/(.*)$ /$1 break;
      		proxy_set_header X-RSC-Request $scheme://$host:$server_port$request_uri;
      		proxy_pass http://localhost:3939;
      		proxy_redirect / /rsconnect/;
      		proxy_set_header Upgrade $http_upgrade;
      		proxy_set_header Connection $connection_upgrade;
      		proxy_http_version 1.1;
    	}

        location / {
                try_files $uri $uri/ =404;
        }
}

Also, just to rule out the basics, have you restarted the nginx server after updating the config file?

Yes, i used the IP from the DO droplet. I think it is a public IP.
I can let "localhost" in the code, instead of the IP address?

Yes, i restarted it after each try!

This block of code enters in the "/etc/nginx/sites-enabled/default" file? And it substitute the whole default code? or i have to add it in some specific place?

I will try this in a few minutes and return here. Thank you.

I think you should

Yes

1 Like

Bingo andresrcs!

This totally worked.

I don't know what was my mistake in the first try, maybe some digitation mistake.

Anyway, thank you very much!

Wish you the best.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.