Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]: Update documentation for Apache2 Reverse Proxy configuration with subdirectory support #3932

Open
joeRob2468 opened this issue Feb 4, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@joeRob2468
Copy link

joeRob2468 commented Feb 4, 2025

Type of Enhancement

Documentation

Describe the Feature/Enhancement

I was having trouble getting websocket support up and running behind an Apache reverse proxy without Docker after the /audiobookshelf subdirectory update, since the >= 2.4.47 Apache directives weren't working for me (I'm on Apache v2.4.29 if that matters). After some troubleshooting and checking out the logs to see what the websocket was actually connecting to, I discovered that setting up a separate Location block for the socket.io websocket subdirectory worked properly. Not sure if this will work for everybody, but it might help people with my usecase, since it works with all the *arr and plex reverse proxies I had set up already, and also works behind the port 443 virtualhost for SSL support.

SSLProxyEngine on
<Location /audiobookshelf>
    ProxyPreserveHost on
    ProxyPass http://localhost:13378/audiobookshelf
    ProxyPassReverse http://localhost:13378/audiobookshelf
</Location>
<Location /audiobookshelf/socket.io>
    ProxyPreserveHost on
    ProxyPass ws://localhost:13378/audiobookshelf/socket.io upgrade=websocket
    ProxyPassReverse ws://localhost:13378/audiobookshelf/socket.io
</Location>

If a full example helps anyone, here's a trimmed down version of a full virtualhost definition with LetsEncrypt certificates via certbot, for plex and related services for AudioBookShelf/Readarr/Jackett.

<VirtualHost [CENSORED_INTERNAL_IP]:443>
    ServerAdmin webmaster@localhost
    ServerName [CENSORED_DOMAIN_NAME]

    ProxyRequests Off
    ProxyPreserveHost On

    # Plex Proxy
    ProxyPass /plex http://localhost:32400
    ProxyPassReverse /plex http://localhost:32400
    ProxyPass /web http://localhost:32400/web
    ProxyPassReverse /web http://localhost:32400/web

    # Plex Websocket proxy
    SSLProxyEngine on
    <Location /plex:/websockets/notifications>
        ProxyPass wss://localhost:32400/:/websockets/notifications
        ProxyPassReverse wss://localhost:32400/:/websockets/notifications
    </Location>

    # Sonarr Proxy
    RewriteEngine on
    RewriteRule ^/admin/sonarr$ /admin/sonarr/ [R]
    <Location /admin/sonarr>
        ProxyPass http://localhost:8989/admin/sonarr
        ProxyPassReverse http://localhost:8989/admin/sonarr
        Header add X-Frame-Options "SAMEORIGIN"
    </Location>

    # Radarr Proxy
    RewriteEngine on
    RewriteRule ^/admin/radarr$ /admin/radarr/ [R]
    <Location /admin/radarr>
        ProxyPass http://localhost:7878/admin/radarr
        ProxyPassReverse http://localhost:7878/admin/radarr
        Header add X-Frame-Options "SAMEORIGIN"
    </Location>
    
    # Readarr Proxy
    RewriteEngine on
    RewriteRule ^/admin/readarr$ /admin/readarr/ [R]
    <Location /admin/readarr>
        ProxyPass http://localhost:8787/admin/readarr
        ProxyPassReverse http://localhost:8787/admin/readarr
        Header add X-Frame-Options "SAMEORIGIN"
    </Location>
    
    # AudioBookShelf Proxy
    # Enable SSLProxyEngine if it's not already turned on for other services in your virtualhost definition
    #SSLProxyEngine on
    RewriteRule ^/audiobookshelf$ /audiobookshelf/ [R]
    <Location /audiobookshelf>
        ProxyPreserveHost on
        ProxyPass http://localhost:13378/audiobookshelf
        ProxyPassReverse http://localhost:13378/audiobookshelf
    </Location>
    <Location /audiobookshelf/socket.io>
        ProxyPreserveHost on
        ProxyPass ws://localhost:13378/audiobookshelf/socket.io upgrade=websocket
        ProxyPassReverse ws://localhost:13378/audiobookshelf/socket.io
    </Location>

    # Jackett Proxy
    RewriteEngine on
    RewriteRule ^/admin/jackett$ /admin/jackett/ [R]
    <Location /admin/jackett>
        ProxyPreserveHost On
        RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}
        ProxyPass http://localhost:9117/admin/jackett
        ProxyPassReverse http://localhost:9117/admin/jackett
    </Location>

    # Enable LetsEncrypt SSL support
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/[CENSORED_DOMAIN_NAME]/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/[CENSORED_DOMAIN_NAME]/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

    # Force SSL headers at all times (completely disables http)
    <IfModule mod_headers.c>
        Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
        #Header always unset X-Frame-Options
    </IfModule>
</VirtualHost>

Why would this be helpful?

Ideally this will help people configure a manual Apache2 reverse proxy (I wasn't able to find any related issues or working documentation for getting this set up manually).

Future Implementation (Screenshot)

Maybe we can add this snippet to the readme under the Apache Reverse Proxy config instructions section!

Audiobookshelf Server Version

v2.19.0

Current Implementation (Screenshot)

No response

@joeRob2468 joeRob2468 added the enhancement New feature or request label Feb 4, 2025
@advplyr
Copy link
Owner

advplyr commented Feb 4, 2025

The websocket worked before updating to 2.18.x + ?

I don't think anything would need to be changed after the subdirectory support was added.

I'm not familiar with Apache but you should be able to remove the /audiobookshelf subdir and it will work the same.

@joeRob2468
Copy link
Author

joeRob2468 commented Feb 5, 2025

I should clarify, this was my first time installing (I was waiting on subdirectory support). I'm not sure if it worked in previous versions or not.

I tried with the /audiobookshelf subdir removed (I tried both examples in the readme), and neither of them worked out for me, removing the /audiobookshelf subdir just gave me a 404. The dashboard/webapp loaded fine (other than the socket error popup in the dashboard), but websockets weren't working until I specifically added the socket.io location block (which I did because the console error was pinging the server address/audiobookshelf/socket.io/[query strings]. Maybe someone who knows a bit more about apache2 can pitch in, I'm definitely not an expert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants