Narzędzia użytkownika

Narzędzia witryny


wiki:python_w_apache

Prosty vhost dla Pythona w Apache

Założenia:

  • aplikacje pythonowe to Jupyter Notebook, nasłuchujące na portach 8001-8012,
  • chcę mieć poszczególne notebooki jako „podkatalogi” python.baszarek.pl,
  • mam certyfikat z Let's Encrypt.
VirtualHost *:80>
  ServerName python.baszarek.pl:80
  Redirect permanent / https://python.baszarek.pl/
</VirtualHost>

<VirtualHost *:443>
  ServerName python.baszarek.pl:443
  ServerAdmin root@localhost
  
  # PreserveHost pomaga przy logowaniu
  ProxyPreserveHost On
  ProxyPass /errno http://127.0.0.1:8001/errno
  ProxyPassReverse /errno http://127.0.0.1:8001/errno
  ProxyPass /glob http://127.0.0.1:8002/glob
  ProxyPassReverse /glob http://127.0.0.1:8002/glob
  ProxyPass /math http://127.0.0.1:8003/math
  ProxyPassReverse /math http://127.0.0.1:8003/math
  ProxyPass /os http://127.0.0.1:8004/os
  ProxyPassReverse /os http://127.0.0.1:8004/os
  ProxyPass /pathlib http://127.0.0.1:8005/pathlib
  ProxyPassReverse /pathlib http://127.0.0.1:8005/pathlib
  ProxyPass /pickle http://127.0.0.1:8006/pickle
  ProxyPassReverse /pickle http://127.0.0.1:8006/pickle
  ProxyPass /random http://127.0.0.1:8007/random
  ProxyPassReverse /random http://127.0.0.1:8007/random
  ProxyPass /shutil http://127.0.0.1:8008/shutil
  ProxyPassReverse /shutil http://127.0.0.1:8008/shutil
  ProxyPass /subprocess http://127.0.0.1:8009/subprocess
  ProxyPassReverse /subprocess http://127.0.0.1:8009/subprocess
  ProxyPass /tkinter http://127.0.0.1:8010/tkinter
  ProxyPassReverse /tkinter http://127.0.0.1:8010/tkinter
  ProxyPass /zlib http://127.0.0.1:8011/zlib
  ProxyPassReverse /zlib http://127.0.0.1:8011/zlib
  ProxyPass /zoneinfo http://127.0.0.1:8012/zoneinfo
  ProxyPassReverse /zoneinfo http://127.0.0.1:8012/zoneinfo

  <Location /errno/api/kernels/>
    ProxyPass ws://127.0.0.1:8001/errno/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8001/errno/api/kernels/
  </Location>

  <Location /errno/terminals/websocket/>
    ProxyPass ws://localhost:8001/errno/terminals/websocket/
    ProxyPassReverse ws://localhost:8001/errno/terminals/websocket/
  </Location>

  <Location /glob/api/kernels/>
    ProxyPass ws://127.0.0.1:8002/glob/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8002/glob/api/kernels/
  </Location>

  <Location /glob/terminals/websocket/>
    ProxyPass ws://localhost:8002/glob/terminals/websocket/
    ProxyPassReverse ws://localhost:8002/glob/terminals/websocket/
  </Location>

  <Location /math/api/kernels/>
    ProxyPass ws://127.0.0.1:8003/math/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8003/math/api/kernels/
  </Location>

  <Location /math/terminals/websocket/>
    ProxyPass ws://localhost:8003/mathterminals/websocket/
    ProxyPassReverse ws://localhost:8003/math/terminals/websocket/
  </Location>

  <Location /os/api/kernels/>
    ProxyPass ws://127.0.0.1:8004/os/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8004/os/api/kernels/
  </Location>

  <Location /os/terminals/websocket/>
    ProxyPass ws://localhost:8004/os/terminals/websocket/
    ProxyPassReverse ws://localhost:8004/os/terminals/websocket/
  </Location>

  <Location /pathlib/api/kernels/>
    ProxyPass ws://127.0.0.1:8005/pathlib/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8005/pathlib/api/kernels/
  </Location>

  <Location /pathlib/terminals/websocket/>
    ProxyPass ws://localhost:8005/pathlib/terminals/websocket/
    ProxyPassReverse ws://localhost:8005/pathlib/terminals/websocket/
  </Location>
  
  <Location /pickle/api/kernels/>
    ProxyPass ws://127.0.0.1:8006/pickle/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8006/pickle/api/kernels/
  </Location>

  <Location /pickle/terminals/websocket/>
    ProxyPass ws://localhost:8006/pickle/terminals/websocket/
    ProxyPassReverse ws://localhost:8006/pickle/terminals/websocket/
  </Location>

  <Location /random/terminals/websocket/>
    ProxyPass ws://localhost:8007/random/terminals/websocket/
    ProxyPassReverse ws://localhost:8007/random/terminals/websocket/
  </Location>

  <Location /random/api/kernels/>
    ProxyPass ws://127.0.0.1:8007/random/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8007/random/api/kernels/
  </Location>

  <Location /shutil/terminals/websocket/>
    ProxyPass ws://localhost:8008/shutil/terminals/websocket/
    ProxyPassReverse ws://localhost:8008/shutil/terminals/websocket/
  </Location>

  <Location /shutil/api/kernels/>
    ProxyPass ws://127.0.0.1:8008/shutil/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8008/shutil/api/kernels/
  </Location>

  <Location /subprocess/terminals/websocket/>
    ProxyPass ws://localhost:8009/subprocess/terminals/websocket/
    ProxyPassReverse ws://localhost:8009/subprocess/terminals/websocket/
  </Location>

  <Location /subprocess/api/kernels/>
    ProxyPass ws://127.0.0.1:8009/subprocess/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8009/subprocess/api/kernels/
  </Location>

  <Location /tkinter/terminals/websocket/>
    ProxyPass ws://localhost:8010/tkinter/terminals/websocket/
    ProxyPassReverse ws://localhost:8010/tkinter/terminals/websocket/
  </Location>

  <Location /tkinter/api/kernels/>
    ProxyPass ws://127.0.0.1:8010/tkinter/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8010/tkinter/api/kernels/
  </Location>

  <Location /zlib/terminals/websocket/>
    ProxyPass ws://localhost:8011/zlib/terminals/websocket/
    ProxyPassReverse ws://localhost:8011/zlib/terminals/websocket/
  </Location>

  <Location /zlib/api/kernels/>
    ProxyPass ws://127.0.0.1:8011/zlib/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8011/zlib/api/kernels/
  </Location>

  <Location /zoneinfo/terminals/websocket/>
    ProxyPass ws://localhost:8012/zoneinfo/terminals/websocket/
    ProxyPassReverse ws://localhost:8012/zoneinfo/terminals/websocket/
  </Location>
  
  <Location /zoneinfo/api/kernels/>
    ProxyPass ws://127.0.0.1:8012/zoneinfo/api/kernels/
    ProxyPassReverse ws://127.0.0.1:8012/zoneinfo/api/kernels/
  </Location>

  CustomLog /var/log/httpd/notebook-access.log combined
  ErrorLog /var/log/httpd/notebook-errors.log

  Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
  SSLEngine on
  SSLProtocol -all +TLSv1.2

  Include /etc/letsencrypt/options-ssl-apache.conf
  SSLCertificateFile /etc/letsencrypt/live/python.baszarek.pl/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/python.baszarek.pl/privkey.pem

</VirtualHost>
wiki/python_w_apache.txt · ostatnio zmienione: 2021/12/02 08:58 przez lukasz