Reverse proxy on apache2 with FQDN not working

72 Views Asked by At

FQDN of my server is myserver.mycompany.com (OS:ubuntu 22.04)

There is a docker container with its own apache running on myserver. This docker container maps its 80 port to 8181 port on myserver. I can access the application running in the container:

http://myserver:8181

http://myserver.mycompany.com:8181

http://myserver:8181/myappindocker - automatically redirects to http://myserver:8181 (set in myappindocker)

http://myserver.mycompany.com:8181/myappindocker - automatically redirects (set in myappindocker)

There is also apache2 on myserver. I would like to set it so that I can access the docker application on: https://myserver.mycompany.com

If I type the following urls:

http://myserver

http://myserver.mycompany.com

http://myserver/myappindocker

http://myserver.mycompany.com/myappindocker

https://myserver

https://myserver.mycompany.com

https://myserver/myappindocker

https://myserver.mycompany.com/myappindocker

it should redirect me to https://myserver.mycompany.com which is the login page (i would like to see it in the address bar of the browser)

Im new to apache and although there's a lot of information nothing worked so far. The best so far is that I created /etc/apache2/mycomp_webapp.conf with the following content:

<VirtualHost *:80>
    ServerName myserver.mycompany.com
    ServerAlias myserver

    RewriteEngine On
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>

<VirtualHost *:443>

    ServerName myserver.mycompany.com
    ServerAlias myserver
    SSLProxyEngine On
    ProxyRequests Off
    ProxyPreserveHost On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass "/" "http://127.0.0.1:8181/"
    ProxyPassReverse "/" "http://127.0.0.1:8181/"
    RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}

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

    SSLCertificateFile  /etc/ssl/certs/myserver.mycompany.com.cer
    SSLCertificateKeyFile /etc/ssl/private/myserver.mycompany.com.key

</VirtualHost>

This file is included at the end of /etc/apache2/sites-available/default-ssl.conf

    </VirtualHost>
    Include /etc/apache2/mycomp_webapps.conf
</IfModule>

This configuration successfully redirects me in case of:

http://myserver

http://myserver/myappindocker

https://myserver

https://myserver/myappindocker

But if I type https://myserver.mycompany.com or http://myserver.mycompany.com then it returns me the default page of the apache2.

Urls https://myserver.mycompany.com/myappindocker or http://myserver.mycompany.com/myappindocker return 404 not found

FQDN simply does not work, tried many settings. Im not sure it should be configured as vhost. Any ideas? Nginx unfortunatelly is not an option.

Thanks!

P.s: later on I would like to either disable or redirect all currently working urls containing the 8181 port but it would be the next step.

0

There are 0 best solutions below