jenkins.io icon indicating copy to clipboard operation
jenkins.io copied to clipboard

Update Apache reverse proxy documentation to include configuration for Websocket

Open Dohbedoh opened this issue 1 year ago • 0 comments

Describe your use-case which is not covered by existing documentation.

Per me understanding from https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html, the modules rewrite and proxy_wstunnel must be loaded and the following should be added (when no prefix):

    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/?(.*) "ws://localhost:8080/$1" [P,L]

Of the following if the prefix is /jenkins

    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/jenkins/?(.*) "ws://localhost:8080/jenkins/$1" [P,L]

I have tested the prefix scenario and made it work. With something like this:

[...]
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
[...]
Listen 8443
<VirtualHost *:8443>
    SSLEngine on
    SSLCertificateFile     /root/ssl/cert.pem
    SSLCertificateKeyFile  /root/ssl/key.pem
    ServerAdmin  webmaster@localhost
    ProxyRequests     Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass         /cm-1  http://localhost:8080/cm-1 nocanon
    ProxyPassReverse  /cm-1  http://localhost:8080/cm-1
    ProxyPassReverse  /cm-1  http://your.host.com:8443/cm-1
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Port "8443"

    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/cm-1/?(.*) "ws://localhost:8080/cm-1/$1" [P,L]
</VirtualHost>

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html https://github.com/jenkins-infra/jenkins.io/pull/3616

Are you interested in contributing a fix?

While I am interested, I am not an apache server expert so it would require some review.

Dohbedoh avatar Oct 02 '24 07:10 Dohbedoh