Apache ReverseProxy to Docker Hedgedoc Instance

My version of HedgeDoc is: hedgedoc:1.9.7 using quay.io

I set up a docker image on a server for hedgedoc which worked locally. Now I am trying to add a reverse proxy in apache2 to the docker image. Unfortunately I get an internal error as follows:

[Wed May 10 11:15:29.999343 2023] [proxy_http:error] [pid 4124860:tid 139799186159360] (104)Connection reset by peer: [remote redacted_ip] AH01102: error reading status line from remote server 127.0.0.1:3000

My docker config looks something like the following:

 - CMD_DOMAIN=redacted_comain
 - CMD_HOST=127.0.0.1
 - CMD_PORT=3000
 - CMD_PROTOCOL_USESSL=true
 - CMD_URL_ADDPORT=false
 - CMD_HSTS_ENABLE=true

My apache2 config looks something like the following:

<VirtualHost redacted_ip:80>
    ServerName redacted_domain

    ErrorLog ${APACHE_LOG_DIR}/error-hedgedoc.log
    CustomLog ${APACHE_LOG_DIR}/access-hegedoc.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =redacted_domain
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost redacted_ip:443>
    ServerName redacted_domain

    ErrorLog ${APACHE_LOG_DIR}/error-hedgedoc.log
    CustomLog ${APACHE_LOG_DIR}/access-hedgedoc.log combined

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

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

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

    SSLCertificateFile redacted_path_to_cert_file
    SSLCertificateKeyFile redacted_path_to_key_file
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

I made sure that proxy, proxy_http and proxy_wstunnel are activated using a2enmod and restarted apache2 afterwards.

Any clues what I am missing?

1 Like

You’ve set

CMD_HOST=127.0.0.1

which means that you’ve told the hedgedoc process to only be available in the container. Docker containers have their own network stack, so 127.0.0.1 points to the container itself.

Just remove this directive. You don’t need it. But set your container port binding to 127.0.0.1:3000:3000.

3 Likes