diff --git a/rstudio/c9s-python-3.11/nginx/serverconf/proxy.conf.template b/rstudio/c9s-python-3.11/nginx/serverconf/proxy.conf.template index 3c2194c35..1383dce09 100644 --- a/rstudio/c9s-python-3.11/nginx/serverconf/proxy.conf.template +++ b/rstudio/c9s-python-3.11/nginx/serverconf/proxy.conf.template @@ -50,7 +50,7 @@ location = /rstudio { location /rstudio/ { rewrite ^/rstudio/(.*)$ /$1 break; # Standard RStudio/NGINX configuration - proxy_pass http://127.0.0.1:8787; + proxy_pass http://localhost:8787; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; diff --git a/rstudio/c9s-python-3.11/nginx/serverconf/proxy.conf.template_nbprefix b/rstudio/c9s-python-3.11/nginx/serverconf/proxy.conf.template_nbprefix index fc4897699..afdcb54f2 100644 --- a/rstudio/c9s-python-3.11/nginx/serverconf/proxy.conf.template_nbprefix +++ b/rstudio/c9s-python-3.11/nginx/serverconf/proxy.conf.template_nbprefix @@ -77,7 +77,7 @@ location = / { location /rstudio/ { rewrite ^/rstudio/(.*)$ /$1 break; # Standard RStudio/NGINX configuration - proxy_pass http://127.0.0.1:8787; + proxy_pass http://localhost:8787; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; diff --git a/rstudio/c9s-python-3.11/setup_rstudio.py b/rstudio/c9s-python-3.11/setup_rstudio.py index c6d3c0d96..c3429e67c 100644 --- a/rstudio/c9s-python-3.11/setup_rstudio.py +++ b/rstudio/c9s-python-3.11/setup_rstudio.py @@ -46,6 +46,30 @@ def _support_arg(arg): ret = subprocess.check_output([get_rstudio_executable('rserver'), '--help']) return ret.decode().find(arg) != -1 +def detect_env(): + import socket + supports_ipv4 = supports_ipv6 = False + try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.bind(('127.0.0.1', 0)) + supports_ipv4 = True + except OSError: + pass + try: + with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + s.bind(('::1', 0)) + supports_ipv6 = True + except OSError: + pass + if supports_ipv4 and supports_ipv6: + return '::' # Dual-stack + elif supports_ipv6: + return '::' + elif supports_ipv4: + return '0.0.0.0' + else: + raise EnvironmentError('No IPv4 or IPv6 support detected.') + def _get_cmd(port): ntf = tempfile.NamedTemporaryFile() @@ -60,7 +84,7 @@ def _get_cmd(port): '--server-working-dir=' + os.getenv('HOME'), '--auth-none=1', '--www-frame-origin=same', - #'--www-address=0.0.0.0', + '--www-address='+ detect_env(), '--www-port=' + str(port), '--www-verify-user-agent=0', '--rsession-which-r=' + get_rstudio_executable('R'),