HTTP is redirected to HTTPS, but HTTPS is unavailable with Nginx and Apache HTTPD in development environment

Hello, I have a problem and I don’t know how to solve it and who to ask.
I’ve been trying to make a development environment but every time I fail. Every time it redirects to https. On https it tells me that the site is unavailable. First with nginx and now with apache. I don’t know where I’m wrong. Maybe my approach is not the best.

I want to configure apache2 to have 3 custom domains, + 1 for mailserver and one for phpmyadmin.

I know it’s not suitable for a development environment but the application I’m trying to make is quite complicated and difficult.

local.dev.conf for tests
wordpress.dev.conf for website
xxx.dev.conf for api
bookmark.dev.conf for core project

phpmyadmin.dev
mailserver.local

This is my structure

/dev-environment
├── docker-compose.yml
├── apache
│ ├── site_config_local.dev.conf
│ ├── site_config_wordpress.dev.conf
│ ├── site_config_xxx.dev.conf
│ ├── site_config_bookmark.dev.conf
├── php
│ ├── Dockerfile
│ ├── php.ini
├── ssl
│ │── local.dev.crt
│ │── local.dev.key
│ │── wordpress.dev.crt
│ │── wordpress.dev.key
│ │── xxx.dev.crt
│ │── xxx.dev.key
│ │── bookmark.dev.crt
│ │── bookmark.dev.key
├── sites
│ ├── localdev
│ ├── wordpress
│ ├── xxx
│ └── bookmark

I m sorry but i can’t upload files.

docker-compose.yml

services:
  apache:
    image: php:8.3-apache
    container_name: apache
    volumes:
      - ./sites:/var/www/html
      - ./apache:/etc/apache2/sites-available
      - ./ssl:/etc/ssl/certs
    ports:
      - "80:80"
      - "443:443"
      - "9003:9003"
    networks:
      - app_network
    environment:
      - VIRTUAL_HOST=local.dev,wordpress.dev,xxx.dev,bookmark.dev
    restart: always

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    environment:
      - VIRTUAL_HOST=phpmyadmin.dev
      - PMA_HOST=apache
      - PMA_PORT=3306
    networks:
      - app_network
    ports:
      - "8080:80"
    restart: always

  mailhog:
    image: mailhog/mailhog
    container_name: mailhog
    ports:
      - "1025:1025"
      - "8025:8025"
    networks:
      - app_network
    environment:
      - VIRTUAL_HOST=mailserver.local
    restart: always

networks:
  app_network:
    driver: bridge

Dockerfile

[PHP]
max_execution_time = 300
memory_limit = 512M
post_max_size = 50M
upload_max_filesize = 50M

[Date]
date.timezone = "Europe/Bucharest"

[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.log=/var/log/xdebug.log

site_config_local.dev.conf

<VirtualHost *:80>
    ServerAdmin webmaster@local.dev
    ServerName local.dev
    DocumentRoot /var/www/html/localdev

    # Redirecționează HTTP către HTTPS
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

    <Directory /var/www/html/localdev>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin webmaster@local.dev
    ServerName local.dev
    DocumentRoot /var/www/html/localdev

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/local.dev.crt
    SSLCertificateKeyFile /etc/ssl/certs/local.dev.key

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

    <Directory /var/www/html/localdev>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

I’m about to give up on this approach, but I’d like to know before I give up that I’ve done everything I can.

I changed the topic title. Please, don’t create general titles that tells nothing about the issue… It will not attract people to solve the problem of “losing your mind” :slight_smile:

You did exactly what we expect, sharing code in code blocks. That we can quote too.

The issue doesn’t seem to be a Docker issue, but a webserver and application configuration issue. Your httpd config redirects all HTTP URLs to HTTPS

Why it is not available with HTTPS, I don’t know. Please, share the exact error message you see. If you only checked it from a browser, you can also try curl.

curl -vvv https://URL

And share the output.

My guess is that you copy the code to a wrong directory or the SSL keys are wrong, or there is an application level error message, not webserver level. The curl output should help to find out.

Update:

Almost forgot, but check the logs too:

docker compose logs
```

Thank you very much for the answer Rimelek!

I changed the topic title I’m → Sorry for that!

The issue doesn’t seem to be a Docker issue → You have right!
You’re right, I just couldn’t find the logic, everything was configured well, there were no errors, but it still didn’t work.
After I calmed down, and after a break, I found the solution.
The problem was my browser redirection.
I disabled the redirect rules in my browser including those that refer strictly to https. And I thought that was enough.

Solution: I changed the tlds from “dev” to “local” and I haven’t had any problems.