How to redirect from http to https port 9443

I am currently working on the AWS EMR service which uses the emr/jupyter-notebook Docker Image for Jupyterhub with Port 9443. The url “https://my-domain.com:9443” works. What I want is that when the user opens the url “http://my-domain.com”, then the user should be directed to a working url with port 9443.

I have looked around the answer for this. And one of the suggested answer was to make a change in the jupyterhub_config.py file.

The jupyterhub_config.py file content, where I have added the redirect for port 80. But that doesn’t work, because I am assuming this redirects to the HTTPS url without the port. Not sure though.

import os
notebook_dir = os.environ.get('DOCKER_NOTEBOOK_DIR')
network_name='jupyterhub-network'

c.Spawner.debug = True
c.Spawner.environment = {'SPARKMAGIC_CONF_DIR':'/etc/jupyter/conf', 'JUPYTER_ENABLE_LAB': 'yes'}

c.JupyterHub.hub_ip = '0.0.0.0'
c.JupyterHub.admin_access = True
c.JupyterHub.ssl_key = '<path to key>'
c.JupyterHub.ssl_cert = '<path to cert>'
c.JupyterHub.port = 9443

c.Authenticator.admin_users = {'<username>'}
#Change done for Redirect.
c.ConfigurableHTTPProxy.command = ['configurable-http-proxy', '--redirect-port', '80']

Do you have a server like an nginx? I guess you could perfectly do such configurations there? Maybe the redirection on the other port could happen under the hood?

I can install nginx server in the instance. Is there any document which you can share which can help me with this. Also, could please elaborate on “redirection on the other port could happen under the hood”?

Following on @1kastner’s response - there are many ways to do this. Can you say a bit more about your setup and also if you have any familiarity doing http redirects in other ways? To get things working, I would stick with whatever you’re comfortable with - and it’s fine if you have multiple proxies running (they won’t affect performance much).

You may be missing the --redirect-to argument in this case. The underlying proxy server here is nice because it has an API to query it - and you can use it directly. If you want a Python interface, at gigantum we wrote this small Python class to query the configurable-http-proxy at runtime, which you’re welcome to copy from (it’s MIT licensed). You may or may not be aware that this is a package you can install and run separately?

But without knowing more about what you can (easily) do, it’s hard to provide a strong recommendation!

1 Like

I tried the --redirect-to option, something like following

c.ConfigurableHTTPProxy.command = ['configurable-http-proxy', '--redirect-port', '80']
c.ConfigurableHTTPProxy.command = ['configurable-http-proxy', '--redirect-to', '9443']

But this didn’t worked. The container stops working automatically.

To be honest, I haven’t worked much on http redirects. Although I would have preferred making changes only in jupyterhub_config.py file or but if that’s not the case and if you could guide me in the right direction, then I can probably work on this.

Regarding the setup, I am using the AWS EMR service for comes with a docker image emr/jupyter-notebook for JupyterHub(1.0.0) for multi-user login. I am not sure if this answers your question on the setup.

Also I am new to this service and I probably don’t know how the underlying proxies work in AWS EMR.

Also thanks for sharing the information on the Python class you guys have created(need to check with the team) and the package details. Regarding the package, how is it different from using the configuration in jupyterhub_config.py file.

Not sure whether I make sense on the questions I have asked, but thanks for the patience.

the above is going to over-write the command atttibute with the second line. I think you want something more like:

c.ConfigurableHTTPProxy.command = [‘configurable-http-proxy’, ‘–redirect-port’, ‘80’, ‘–redirect-to’, ‘9443’]

If you’re on AWS, you can actually do a redirect with a load balancer (you can configure via the web console).

But in ANY case, I would ensure that you have a server up and running, and start by configuring your own proxy first (you can just run configurable-http-proxy from the command line once it’s installed). Then if you want to integrate it into your Jupyter configuration you can. This will make your debugging more direct and efficient.

1 Like