Skip to content

Commit

Permalink
Set correctly for redirects on vscode and rstudio nginx (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
atheo89 authored Sep 27, 2023
1 parent c507e77 commit 33cad7a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
5 changes: 5 additions & 0 deletions codeserver/c9s-python-3.9/nginx/httpconf/http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ log_format json escape=json '[{'
'"execution_state":"busy",'
'"connections": 1'
'}]';

map $http_x_forwarded_proto $custom_scheme {
default $scheme;
https https;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ location /api/ {
# api calls from culler get to CGI processing
###############
location = /api/kernels {
return 302 $scheme://$http_host/api/kernels/;
return 302 $custom_scheme://$http_host/api/kernels/;
access_log off;
}

Expand All @@ -36,11 +36,11 @@ location /api/kernels/ {
# root and prefix get to VSCode endpoint
###############
location = / {
return 302 $scheme://$http_host/vscode/;
return 302 $custom_scheme://$http_host/vscode/;
}

location = /vscode {
return 302 $scheme://$http_host/vscode/;
return 302 $custom_scheme://$http_host/vscode/;
}

location /vscode/ {
Expand All @@ -54,10 +54,11 @@ location /vscode/ {
# Needed to make it work properly
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 $custom_scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;

access_log /var/log/nginx/vscode.access.log json if=$loggable;
}
###############
###############
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ location ${NB_PREFIX}/api/ {
# api calls from culler get to CGI processing
###############
location = ${NB_PREFIX}/api/kernels {
return 302 $scheme://$http_host/api/kernels/;
return 302 $custom_scheme://$http_host/api/kernels/;
access_log off;
}

location ${NB_PREFIX}/api/kernels/ {
return 302 $scheme://$http_host/api/kernels/;
return 302 $custom_scheme://$http_host/api/kernels/;
access_log off;
}

Expand All @@ -41,19 +41,19 @@ location /api/kernels/ {
# root and prefix get to VSCode endpoint
###############
location = ${NB_PREFIX} {
return 302 $scheme://$http_host/vscode/;
return 302 $custom_scheme://$http_host/vscode/;
}

location ${NB_PREFIX}/ {
return 302 $scheme://$http_host/vscode/;
return 302 $custom_scheme://$http_host/vscode/;
}

location = /vscode {
return 302 $scheme://$http_host/vscode/;
return 302 $custom_scheme://$http_host/vscode/;
}

location = / {
return 302 $scheme://$http_host/vscode/;
return 302 $custom_scheme://$http_host/vscode/;
}

location /vscode/ {
Expand All @@ -64,6 +64,7 @@ location /vscode/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_set_header X-Forwarded-Proto $custom_scheme;

access_log /var/log/nginx/vscode.access.log json if=$loggable;
}
Expand Down
5 changes: 5 additions & 0 deletions rstudio/c9s-python-3.9/nginx/httpconf/http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ log_format json escape=json '[{'
'"execution_state":"busy",'
'"connections": 1'
'}]';

map $http_x_forwarded_proto $custom_scheme {
default $scheme;
https https;
}
13 changes: 7 additions & 6 deletions rstudio/c9s-python-3.9/nginx/serverconf/proxy.conf.template
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
###############
# Fix rstudio-server auth-sign-in redirect bug
###############
rewrite ^/auth-sign-in(.*) "$scheme://$http_host/rstudio/auth-sign-in$1?appUri=%2Frstudio";
rewrite ^/auth-sign-out(.*) "$scheme://$http_host/rstudio/auth-sign-out$1?appUri=%2Frstudio";
rewrite ^/auth-sign-in(.*) "$custom_scheme://$http_host/rstudio/auth-sign-in$1?appUri=%2Frstudio";
rewrite ^/auth-sign-out(.*) "$custom_scheme://$http_host/rstudio/auth-sign-out$1?appUri=%2Frstudio";
###############

###############
Expand All @@ -20,7 +20,7 @@ location /api/ {
}

location = /api/kernels {
return 302 $scheme://$http_host/api/kernels/;
return 302 $custom_scheme://$http_host/api/kernels/;
access_log off;
}

Expand All @@ -40,11 +40,11 @@ location /api/kernels/ {
# api calls from culler get to CGI processing
###############
location = / {
return 302 $scheme://$http_host/rstudio/;
return 302 $custom_scheme://$http_host/rstudio/;
}

location = /rstudio {
return 302 $scheme://$http_host/rstudio/;
return 302 $custom_scheme://$http_host/rstudio/;
}

location /rstudio/ {
Expand All @@ -57,9 +57,10 @@ location /rstudio/ {
proxy_read_timeout 20d;

# Needed to make it work properly
proxy_set_header X-RStudio-Request $scheme://$http_host$request_uri;
proxy_set_header X-RStudio-Request $custom_scheme://$http_host$request_uri;
proxy_set_header X-RStudio-Root-Path /rstudio;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $custom_scheme;

access_log /var/log/nginx/rstudio.access.log json if=$loggable;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
###############
# Fix rstudio-server auth-sign-in redirect bug
###############
rewrite ^/auth-sign-in(.*) "$scheme://$http_host/rstudio/auth-sign-in$1?appUri=%2Frstudio";
rewrite ^/auth-sign-out(.*) "$scheme://$http_host/rstudio/auth-sign-out$1?appUri=%2Frstudio";
rewrite ^/auth-sign-in(.*) "$custom_scheme://$http_host/rstudio/auth-sign-in$1?appUri=%2Frstudio";
rewrite ^/auth-sign-out(.*) "$custom_scheme://$http_host/rstudio/auth-sign-out$1?appUri=%2Frstudio";
###############

###############
Expand Down Expand Up @@ -34,12 +34,12 @@ location /api/ {
# api calls from culler get to CGI processing
###############
location = ${NB_PREFIX}/api/kernels {
return 302 $scheme://$http_host/api/kernels/;
return 302 $custom_scheme://$http_host/api/kernels/;
access_log off;
}

location ${NB_PREFIX}/api/kernels/ {
return 302 $scheme://$http_host/api/kernels/;
return 302 $custom_scheme://$http_host/api/kernels/;
access_log off;
}

Expand All @@ -59,19 +59,19 @@ location /api/kernels/ {
# root and prefix get to RStudio endpoint
###############
location = ${NB_PREFIX} {
return 302 $scheme://$http_host/rstudio/;
return 302 $custom_scheme://$http_host/rstudio/;
}

location ${NB_PREFIX}/ {
return 302 $scheme://$http_host/rstudio/;
return 302 $custom_scheme://$http_host/rstudio/;
}

location = /rstudio {
return 302 $scheme://$http_host/rstudio/;
return 302 $custom_scheme://$http_host/rstudio/;
}

location = / {
return 302 $scheme://$http_host/rstudio/;
return 302 $custom_scheme://$http_host/rstudio/;
}

location /rstudio/ {
Expand All @@ -84,9 +84,10 @@ location /rstudio/ {
proxy_read_timeout 20d;

# Needed to make it work properly
proxy_set_header X-RStudio-Request $scheme://$http_host$request_uri;
proxy_set_header X-RStudio-Request $custom_scheme://$http_host$request_uri;
proxy_set_header X-RStudio-Root-Path /rstudio;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $custom_scheme;

access_log /var/log/nginx/rstudio.access.log json if=$loggable;
}
Expand Down

0 comments on commit 33cad7a

Please sign in to comment.