TFNS / CTFNote

CTFNote is a collaborative tool aiming to help CTF teams to organise their work.
GNU General Public License v3.0
520 stars 61 forks source link

Problem connecting to Hedgedoc over Apache #285

Closed r3-ck0 closed 2 months ago

r3-ck0 commented 2 months ago

Hi, I am trying to setup ctfnote but ran into an issue where hedgedoc keeps spinning indefinitely and won't load.

I'm on the way so I can't post my exact config but what I've done is forward http traffic through the apache proxy module to port 8080.

Most things worked well, but when looking in the console when trying to access hedgedoc, it seems that my browser can reach neither the wss:// endpoint on host/pad/socket.io, nor the /graphql endpoint. I used the ws module on apache to forward ws traffic from /pad/socket.io to localhost:3000/pad/socket.io but to no avail.

Is there something I'm missing here?

r3-ck0 commented 2 months ago

I got another chance to look into it and here is the apache2 config that made it work for me:

<VirtualHost *:443>
    ServerName www.myawesomesite.me
    ServerAdmin server_admin@server.com

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/myawesomesite.cer
    SSLCertificateKeyFile /etc/ssl/private/myawesomesite.key
    SSLCertificateChainFile /etc/ssl/certs/myawesomesite.cer

    # Proxy configuration
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/socket.io             [NC]
    RewriteCond %{HTTP:Upgrade} =websocket             [NC]
    RewriteRule /(.*)  ws://127.0.0.1:3000/$1          [P,L]

    ProxyPass /pad/ http://127.0.0.1:3000/
    ProxyPassReverse /pad/ http://127.0.0.1:3000/

    RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}

    # Optional: Customize the log files
    ErrorLog ${APACHE_LOG_DIR}/ctfnote_error.log
    CustomLog ${APACHE_LOG_DIR}/ctfnote_access.log combined
</VirtualHost>

The first part is for redirecting https traffic to ctfnote itself, while the second part takes care of redirecting the websockets traffic to the hedgedoc instance running on port 3000. The second part was mainly taken from the bottom of this page.