How to run IPython behind an Apache proxy

前端 未结 6 1334
耶瑟儿~
耶瑟儿~ 2020-12-05 11:27

I would like to run an IPython notebook web server behind an Apache (reverse) proxy so that instead of the URL

https://my.server:XXXX

(where XXX

6条回答
  •  一向
    一向 (楼主)
    2020-12-05 12:16

    WARNING: This is rather verbose, as I gather you have figured much of this, but for documentation purposes, I laid out enough detail here for someone else to follow.

    I put this answer together after implementing this myself with the help from various links. The first from here Websocket origin check fails when used with Apache WS proxy #5525. I repeat much of it here with some changes. Other links are referenced below.

    1. Set up iPython:

    This is in the post, but rather than do it as the original post suggested, I just followed the general instructions for Running a notebook server. With this done you should be able to test the setup, which will require enabling the port you have this configured for. If this does not work, then any Apache set up will not work.

    2. Configure Apache:

    1. Make sure you have the following mods available and enabled.

    ./configure --enable-proxy --enable-ssl --enable-deflate --enable-proxy-http --enable-proxy-wstunnel --enable-info --enable-rewrite --enable-headers

    Added --enable-headers here as they were not installed on mine. Also I used the Apache2 a2enmod command. So sudo a2enmod headers, sudo a2enmod proxy, etc.

    If you're running a version of Apache prior to 2.4, you do not have the proxy_wstunnel mod. You can either a patch your version or upgrade. To patch your version, you can follow these instructions. Be sure to copy over both mod_proxy.so and mod_proxy_wstunnel.so. To get the configure script, you need to run ./buildconfig, which has its own dependencies. This is noted in a comment therein.

    1. Within Apache, create a "sites-available/iPython.conf" file. Originally I said to either add to httpd.conf or ports.conf. Adding your own site file is much cleaner and will allow you to enable/disable the configuration when desired.

      Listen [ANY PORT HERE] # post has port 8999 here... ... SSLProxyEngine On # post did not have this... ProxyPass / http://127.0.0.1:8888/ ProxyPassReverse / http://127.0.0.1:8888/ # spoof headers to make notepad accept the request as coming from the same origin Header set Origin "http://127.0.0.1:8888/" RequestHeader set Origin "http://127.0.0.1:8888/" LogLevel debug

      NOTE 1: The post uses port 8999, but it can be any port you want. You want port 80 here, but you do not need to specify it, so, modifying the above would yield:

      ... # Everything is the same here...

      NOTE 2: Since you are using SSL, you need to add SSLProxyEngine On within the body of the VirtualHost definition. As noted above, the post did not have this specifically.

      NOTE 3: Port 8888 is whatever port ipython is running on. Change this based on your configuration.

      NOTE 4: If you want to host multiple applications, and this is one of them, rather than having / and :8888/, you will want /ipython and :8888/ipython or whatever you want this to be named. In order to support this, see Running with a different URL prefix.

    2. Enable the new configuration: sudo a2ensite iPython

    If you need to disable: sudo a2dissite iPython

    1. Reload Apache: sudo service apache2 reload

    My Environment:

    Ubuntu 14.04.1 Apache 2.4.7 ipython 2.3.0

    EDIT: Updated to reflect the final changes I made to get this working. I also changed the instruction order to what I think makes more sense.

提交回复
热议问题