Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect http acces to phpmyadmin in https #414

Closed
Cyanat opened this issue Jun 22, 2023 · 4 comments
Closed

Redirect http acces to phpmyadmin in https #414

Cyanat opened this issue Jun 22, 2023 · 4 comments
Assignees
Labels

Comments

@Cyanat
Copy link

Cyanat commented Jun 22, 2023

Hello!
I try to enable https access on the phpmyadmin docker and redirect all http request on https. Here is what I've done

/etc/apache2/ports.conf : I listen ports 80 and 443

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80
Listen 443

/etc/apache2/sites-enabled/ssl.conf : enable mod_ssl and specifying my cert and key

LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so
<VirtualHost *:443>
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    SSLEngine on
    SSLCertificateFile "certs/MyCert.crt"
    SSLCertificateKeyFile "certs/MyCert.key"
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
    </Directory>
</VirtualHost>

port mapping of my docker-compose:

ports:
            - 8091:80
            - 8092:443

/etc/apache2/sites-enabled/000-default.conf : I set my redirection

<VirtualHost *:80>

        LoadModule rewrite_module modules/mod_rewrite.so
        RewriteEngine On
        RewriteRule ^/?(.*) https://%{SERVER_NAME}:8092/$1 [R=301,L]

</VirtualHost>

I use the DockerFile to update these files in the container and enabling the rewrite mod:

FROM phpmyadmin:5.2.1

RUN mv /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/
ADD 000-default.conf /etc/apache2/sites-enabled/000-default.conf
ADD ssl.conf /etc/apache2/sites-enabled/ssl.conf
ADD ports.conf /etc/apache2/ports.conf

Well... It seems to work. But I would appreciate some feedback to confirm that this solution is clean and maintainable enough or if we have better solution to do that.

Thanks!

@williamdes
Copy link
Member

Hi

Well, I think the following block is not needed

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
    </Directory>

@Cyanat
Copy link
Author

Cyanat commented Jun 23, 2023

You're right, thanks.
If no other feedback, then I will close this issue and use this solution, will see with time if it respond completely to my needs ;)

@Cyanat Cyanat closed this as completed Jun 23, 2023
@williamdes
Copy link
Member

Okay, let us know
Maybe we could provide a disabled SSL config or redirector
That's not really easy
Or at least document it with your examples

@williamdes
Copy link
Member

I would also say it's not necessary to do a Dockerfile, you can mount the files directly and it will work
That said it would be good to find another way to not use mod rewrite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants