Score:0

Apache, Docker, Proxy - change adress in browser to 127.0.0.1

tr flag

I have Apache server with few sites.

I would like to run on this server docker container with Mercure and share it on the Internet.

I found information on the Internet that I need to use ProxyPass and ProxyPassReverse in the vhost configuration.

My vhost configuration:

<VirtualHost *:80>
    ServerName tomaszf.pl
    ServerAlias www.tomaszf.pl

    DocumentRoot /var/www/html/mercurytest/public

    DirectoryIndex /index.php

    <Directory /var/www/html/mercurytest/public>
        AllowOverride None
        Order Allow,Deny
        Allow from All

        FallbackResource /index.php
    </Directory>

    <FilesMatch \.php$>
        SetHandler "proxy:unix:/var/run/php/php8.0-fpm.sock|fcgi://localhost"
    </FilesMatch>

    <Directory /var/www/html/mercurytest/public/bundles>
        DirectoryIndex disabled
        FallbackResource disabled
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/tomaszf.pl.error.log
    CustomLog ${APACHE_LOG_DIR}/tomaszf.pl.log combined
 
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.tomaszf.pl [OR]
    RewriteCond %{SERVER_NAME} =tomaszf.pl
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
    ServerName tomaszf.pl
    ServerAlias www.tomaszf.pl

    DocumentRoot /var/www/html/mercurytest/public

    DirectoryIndex /index.php

    <Directory /var/www/html/mercurytest/public>
        AllowOverride None
        Order Allow,Deny
        Allow from All

        FallbackResource /index.php
    </Directory>

    <FilesMatch \.php$>
        SetHandler "proxy:unix:/var/run/php/php8.0-fpm.sock|fcgi://localhost"
    </FilesMatch>

    <Directory /var/www/html/mercurytest/public/bundles>
        DirectoryIndex disabled
        FallbackResource disabled
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/tomaszf.pl.error.log
    CustomLog ${APACHE_LOG_DIR}/tomaszf.pl.log combined

    SSLCertificateFile /etc/letsencrypt/live/tomaszf.pl/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/tomaszf.pl/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

    ProxyPass /mercure http://127.0.0.1:8099/
    ProxyPassReverse /mercure http://127.0.0.1:8099/
</VirtualHost>

Docker container is launched with the command:

docker run \
    -e SERVER_NAME=':80' \
    -e MERCURE_PUBLISHER_JWT_KEY='!ChangeMe!' \
    -e MERCURE_SUBSCRIBER_JWT_KEY='!ChangeMe!' \
    -p 8099:80 \
    -e CORS_ALLOWED_ORIGINS='https://tomaszf.pl' \
    -e DEBUG=1 \
    -e ALLOW_ANONYMOUS=1 \
    dunglas/mercure caddy run -config /etc/caddy/Caddyfile.dev

Problem: When you try to enter the website tomaszf.pl/mercure, the address in the browser is automatically changed to 127.0.0.1 and website not working.

What do I have to change in the configuration?

Score:0
vn flag

I've implemented the same configuration, with the exception of a self-signed certificate and modifying my hosts file to point tomaszf.pl to 127.0.9.1 and I'm not being redirected off of that host.

curl response

That proves that the latest version of the container dunglas/mercure:latest from dockerhub is redirecting correctly. If you are having issues with this, verify you have the latest image (hash c10597bdf077 for amd64 at the time of writing).

The other issue you are going to face is that the caddy module mecure does not appear to support serving the module anywhere but the root of the host (i.e. tomaszf.pl only, not tomaszf.pl/mercure ). This seems to be a design decision based on the use of the /.well-known prefix (Mercure Caddy Module documentation https://caddyserver.com/docs/modules/http.handlers.mercure)

I would recommend using a subdomain (perhaps mercure.tomaszf.pl) and serve the module from there, at the root, instead.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.