CORS errors for js files then using Apache reverse PROXY

Getting CORS errors for js files when serving panel with Apache virtual host reverse Proxy on Ubuntu 22.10

Anybody got this to work ?

export BOKEH_RESOURCES=cdn; panel serve daily_pos.py --allow-websocket-origin=myhost.com --admin --num-procs=4 --log-level=debug

virtual host file and errors below.

<VirtualHost *:443>
    ServerName myhost.com
    Header set Access-Control-Allow-Origin "*"
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPreserveHost On

    ProxyPass /daily_pos/ws ws://127.0.0.1:5006/daily_pos/ws
    ProxyPassReverse /daily_pos/ws ws://127.0.0.1:5006/daily_pos/ws

    ProxyPass /daily_pos http://localhost:5006/daily_account_pnl_pos
    ProxyPassReverse /daily_pos http://localhost:5006/daily_pos

    <Directory />
        Require all granted
        Options -Indexes
    </Directory>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/myhost.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/myhost.com/privkey.pem
</VirtualHost>

Here is a modified virtual host file that works. Had to fix a few things from this solution: Authentication for an app behind reverse proxy

No need for export BOKEH_RESOURCES=cdn;
I was missing the mapping for the local static directory.

<VirtualHost *:443>
    ServerName my_host.com

    ProxyPass /daily_account_pnl_pos/ws ws://127.0.0.1:5006/daily_account_pnl_pos/ws
    ProxyPassReverse /daily_account_pnl_pos/ws ws://127.0.0.1:5006/daily_account_pnl_pos/ws

    ProxyPass /daily_account_pnl_pos/static http://127.0.0.1:5006/static
    ProxyPassReverse /daily_account_pnl_pos/static http://127.0.0.1:5006/static

    ProxyPassMatch /daily_account_pnl_pos/(.*)$ http://127.0.0.1:5006/daily_account_pnl_pos/$1
    ProxyPassReverse /daily_account_pnl_pos/(.*)$ http://127.0.0.1:5006/daily_account_pnl_pos/$1

    Redirect /daily_account_pnl_pos /daily_account_pnl_pos/

    Alias /static /home/me/mambaforge/lib/python3.10/site-packages/bokeh/server/static
    <Directory "/home/me/mambaforge/lib/python3.10/site-packages/bokeh/server/static">
    Require all granted
    Options +Indexes
    </Directory>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/my_host.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/my_host.com/privkey.pem
</VirtualHost>
2 Likes

Hi,

Since I posted this solution I’ve realised that the ProxyPass directives related to /static as well as the Redirect are not necessary. Also, it turns out you don’t need to use a ProxyPassMatch directive.

I think the critical piece that was missing in your initial configuration is the alias for static with the corresponding Directory declaration below.

1 Like

This is great, thank you! Could you maybe contribute some of what you’ve learned to the reverse proxy how-to guide? panel/proxy.md at main · holoviz/panel · GitHub

1 Like

Final cleaned up version of virtual host file for Apache 2.4:

<VirtualHost *:443>
    ServerName my-host.com

    ProxyPass /daily_account_pnl_pos/ws ws://127.0.0.1:5006/daily_account_pnl_pos/ws
    ProxyPassReverse /daily_account_pnl_pos/ws ws://127.0.0.1:5006/daily_account_pnl_pos/ws

    ProxyPass / http://127.0.0.1:5006/
    ProxyPassReverse / http://127.0.0.1:5006/

    Alias /static /home/smbcapital/mambaforge/lib/python3.10/site-packages/bokeh/server/static
    <Directory "/home/smbcapital/mambaforge/lib/python3.10/site-packages/bokeh/server/static">
    Require all granted
    Options +Indexes
    </Directory>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/my-host.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/my-host.com/privkey.pem
</VirtualHost>

I will gladly contribute to the reverse proxy how-to guide.

3 Likes