Shopware hinter Reverse Proxy nutzt http statt https

Hallo,

Ich habe einen Docker Container mit:

  • apache2 auf Port 888 (ohne SSL) und Shopware 6

und einen weiteren mit:

  • einem Caddy Webserver der als Reverse Proxy dient und auf Port 80 und 443 läuft (80 ausschließlich als Redirect von HTTP => HTTPS)

Während dem Installationsprozess wird nun ein Request an http://store.example.com/installer/database-migrate gemacht, was eh erstmal kein Browser zulässt (da es sich hierbei um HTTP handelt, aber der Installer ja über HTTPS aufgerufen ist)

Wie kann ich dafür sorgen, dass Shopware auch wenn es selber nicht direkt mit HTTPS läuft (da es ja erst über den Reverse Proxy kommt) trotzdem https:// statt http:// benutzt?

Edit: APP_URL und STOREFRONT_PROXY_URL in der .env sind bereits auf https://store.example.com gesetzt.

1 „Gefällt mir“

Hi, das ist zwar Lösung für das Problem aber ich habe ein ähnliches Setup mit Caddy als reverse proxy und erhalte einen mixed content Fehler, konntest du das Problem in der Zwischenzeit lösen?

Wenn ja, wie genau?

Hast du TRUSTED_PROXIES in deiner .env definiert?

Ja, sowohl in der .env, wie auch in der .env.local, vermutlich ist es nur in der .env.local notwendig, oder?

So sieht das aktuelle Setup aus

Ohne Caddy als reverse proxy funktioniert es fehlerfrei, das Frontend und Backend wird fehlerfrei geladen, schalte ich Caddy als reverse proxy dazu, tritt der Fehler mit mixed content auf, das Theme wird nicht vollständig geladen.

.env

###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
# doctrine://default?auto_setup=0
###< symfony/messenger ###

###> symfony/mailer ###
# MAILER_DSN=null://null
###< symfony/mailer ###

###> symfony/lock ###
# Choose one of the stores below
# postgresql+advisory://db_user:db_password@localhost/db_name
LOCK_DSN=flock
###< symfony/lock ###

TRUSTED_PROXIES=127.0.0.1,127.0.0.2,192.168.112.5,192.168.112.6,192.168.112.3,192.168.160.2
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2,192.168.112.5,192.168.112.6,192.168.112.3
TRUSTED_HOSTS=vanill.at,www.vanill.at

###> shopware/core ###
APP_ENV=prod
APP_URL=http://127.0.0.1:8000
APP_SECRET=<redacted>
INSTANCE_ID=<redacted>
BLUE_GREEN_DEPLOYMENT=0
DATABASE_URL=mysql://root:root@localhost/shopware
# With Shopware 6.4.17.0 the MAILER_DSN variable will be used in this template instead of MAILER_URL
MAILER_URL=null://null
###< shopware/core ###

###> shopware/elasticsearch ###
OPENSEARCH_URL=http://localhost:9200
SHOPWARE_ES_ENABLED=0
SHOPWARE_ES_INDEXING_ENABLED=0
SHOPWARE_ES_INDEX_PREFIX=sw
SHOPWARE_ES_THROW_EXCEPTION=1
###< shopware/elasticsearch ###

###> shopware/storefront ###
STOREFRONT_PROXY_URL=http://localhost
SHOPWARE_HTTP_CACHE_ENABLED=1
SHOPWARE_HTTP_DEFAULT_TTL=7200
###< shopware/storefront ###

.env.local

APP_SECRET=<redacted>
APP_URL=https://vanill.at
DATABASE_URL=mysql://<redacted>:<redacted>@lcmp-mysql-1:3306/shopwaredb
COMPOSER_HOME=/var/www/html/var/cache/composer
INSTANCE_ID=<redacted>
BLUE_GREEN_DEPLOYMENT=0
OPENSEARCH_URL=http://localhost:9200
ADMIN_OPENSEARCH_URL=http://localhost:9200
TRUSTED_PROXIES=127.0.0.1,127.0.0.2,192.168.112.5,192.168.112.6,192.168.112.3,192.168.160.2
TRUSTED_DOMAINS=vanill.at
TRUSTED_HEADERS='["x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "x-forwarded-port", "x->

Ich habe auch eine framework.yaml erstellt in /srv/lcmp/www/config/packages , ohne Erfolg (die Datei gab es wider Erwarten nicht im Ordner /packages, habe diese selber erstellt)

# config/packages/framework.yaml
framework:
    # ...
    # the IP address (or range) of your proxy
    trusted_proxies: '127.0.0.1,127.0.0.2,192.168.112.5,192.168.112.6,192.168.112.3,192.168.160.2'
    # trust *all* "X-Forwarded-*" headers
    trusted_headers: ['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port',>

Setz mal 0.0.0.0/0 als Trusted Proxy, wenn das dann klappt, dann hast du die falschen IPs hinterlegt.

1 „Gefällt mir“

Deine Trusted Headers sind nur vom kopieren aus der Konsole abgeschnitten oder?

1 „Gefällt mir“

So sieht die .env aktuell aus

###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
# doctrine://default?auto_setup=0
###< symfony/messenger ###

###> symfony/mailer ###
# MAILER_DSN=null://null
###< symfony/mailer ###

###> symfony/lock ###
# Choose one of the stores below
# postgresql+advisory://db_user:db_password@localhost/db_name
LOCK_DSN=flock
###< symfony/lock ###

TRUSTED_PROXIES=0.0.0.0/0
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2,192.168.112.5,192.168.112.6,192.168.112.3,192.168.160.2
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2,192.168.112.5,192.168.112.6,192.168.112.3
TRUSTED_HOSTS=vanill.at,www.vanill.at

###> shopware/core ###
APP_ENV=prod
APP_URL=http://127.0.0.1:8000
APP_SECRET=<redacted>
INSTANCE_ID=<redacted>
BLUE_GREEN_DEPLOYMENT=0
DATABASE_URL=mysql://root:root@localhost/shopware
# With Shopware 6.4.17.0 the MAILER_DSN variable will be used in this template instead of MAILER_URL
MAILER_URL=null://null
###< shopware/core ###

###> shopware/elasticsearch ###
OPENSEARCH_URL=http://localhost:9200
SHOPWARE_ES_ENABLED=0
SHOPWARE_ES_INDEXING_ENABLED=0
SHOPWARE_ES_INDEX_PREFIX=sw
SHOPWARE_ES_THROW_EXCEPTION=1
###< shopware/elasticsearch ###

###> shopware/storefront ###
STOREFRONT_PROXY_URL=http://localhost
SHOPWARE_HTTP_CACHE_ENABLED=1
SHOPWARE_HTTP_DEFAULT_TTL=7200
###< shopware/storefront ###

so sieht die .env.local aktuell aus

APP_SECRET=<redacted>
APP_URL=https://vanill.at
DATABASE_URL=mysql://<redacted>:<redacted>@lcmp-mysql-1:3306/shopwaredb
COMPOSER_HOME=/var/www/html/var/cache/composer
INSTANCE_ID=<redacted>
BLUE_GREEN_DEPLOYMENT=0
OPENSEARCH_URL=http://localhost:9200
ADMIN_OPENSEARCH_URL=http://localhost:9200
TRUSTED_PROXIES=0.0.0.0/0
TRUSTED_DOMAINS=vanill.at
TRUSTED_HEADERS='["x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "x-forwarded-port", "x-forwarded-prefix"]'

Ja, die waren wegen dem Kopieren abgeschnitten.

So sieht das Netzwerk caddy aus

[
    {
        "Name": "caddy",
        "Id": "51d3eb268905ce067549daae818be0e613f010a7313b89d60813b77c68ac6897",
        "Created": "2024-03-24T19:07:33.964517939+01:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.160.0/20",
                    "Gateway": "192.168.160.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "29c1ab73a8d0806796e4a44375d929ca0be19d5fa0d10f72fd8b173681b955fd": {
                "Name": "srv-caddy-1",
                "EndpointID": "d7085d73c9b5d24917c5b4a75e97d3d786ac3174421948547d635e64fb28c3ff",
                "MacAddress": "02:42:c0:a8:a0:02",
                "IPv4Address": "192.168.160.2/20",
                "IPv6Address": ""
            },
            "4e098bf3bb07a4e081e7281371fba6e2c9cc1c79513be9164dae32b068692e9f": {
                "Name": "lcmp-caddy-1",
                "EndpointID": "139cd0aed64eccf6635e2658fda9c6cacfd6e2c13586a88c302977e53df95b7e",
                "MacAddress": "02:42:c0:a8:a0:04",
                "IPv4Address": "192.168.160.4/20",
                "IPv6Address": ""
            },
            "db9f6bda393229a14613234285a1d32b12fd4c1909f8c4915de3579f82d54e77": {
                "Name": "lcmp-php-1",
                "EndpointID": "9e1069a4d869075cb73ddaea120d121fc88ab1803b6ff04e3e1dd71e41b1a2a3",
                "MacAddress": "02:42:c0:a8:a0:03",
                "IPv4Address": "192.168.160.3/20",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

Das ist die interne IP-Adresse des Caddy proxies

docker container inspect 29c1ab73a8d0 | grep "IPAddress"
            "SecondaryIPAddresses": null,
            "IPAddress": "",
                    "IPAddress": "192.168.160.2",

Fehler unverändert

@MBDealer Herzlichen Dank für Deinen Tipp mit der .env.local, das war Teil der Lösung. Ich musste zusätzlich auch

php_fastcgi  php:9000 {
	trusted_proxies private_ranges
}

im Caddyfile in /srv/lcmp/caddy_docker ändern, damit der PHP Service die Header korrekt weiterleitet

Schöne Grüße

1 „Gefällt mir“

Ich habe jetzt wieder den Fehler, dass Inhalte über http angefordert werden statt https, obwohl ich in der

# config/packages/framework.yaml
framework:
    # ...
    # the IP address (or range) of your proxy
    trusted_proxies: '0.0.0.0/0'
    # trust *all* "X-Forwarded-*" headers
    trusted_headers: ['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port', 'x-forwarded-prefix']
    # or, if your proxy instead uses the "Forwarded" header
    #trusted_headers: ['forwarded']

gesetzt habe und in der .env.local

APP_SECRET=<redacted>
APP_URL=https://shop3.vanill.at
DATABASE_URL=mysql://shopwaredbuser:<redacted>@lcmp-mysql-3:3306/shopwaredb
COMPOSER_HOME=/var/www/html/var/cache/composer
#INSTANCE_ID=<redacted>
BLUE_GREEN_DEPLOYMENT=0
OPENSEARCH_URL=http://localhost:9200
ADMIN_OPENSEARCH_URL=http://localhost:9200
TRUSTED_PROXIES=0.0.0.0/0
TRUSTED_DOMAINS=shop3.vanill.at
TRUSTED_HEADERS='["x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "x-forwarded-port", "x-forwarded-prefix"]'

sowie in der .env

###> shopware/core ###
APP_ENV=prod
APP_URL=https://127.0.0.1:8000
APP_SECRET=<redacted>
INSTANCE_ID=<redacted>
BLUE_GREEN_DEPLOYMENT=0
DATABASE_URL=mysql://root:root@localhost/shopware
# With Shopware 6.4.17.0 the MAILER_DSN variable will be used in this template instead of MAILER_URL
MAILER_URL=null://null
###< shopware/core ###


TRUSTED_PROXIES=0.0.0.0/0
TRUSTED_DOMAINS=shop3.vanill.at
TRUSTED_HEADERS='["x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "x-forwarded-port", "x-forwarded-prefix"]'

###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
# doctrine://default?auto_setup=0
###< symfony/messenger ###

###> symfony/mailer ###
# MAILER_DSN=null://null
###< symfony/mailer ###

###> symfony/lock ###
# Choose one of the stores below
# postgresql+advisory://db_user:db_password@localhost/db_name
LOCK_DSN=flock
###< symfony/lock ###

###> shopware/elasticsearch ###
OPENSEARCH_URL=http://localhost:9200
SHOPWARE_ES_ENABLED=0
SHOPWARE_ES_INDEXING_ENABLED=0
SHOPWARE_ES_INDEX_PREFIX=sw
SHOPWARE_ES_THROW_EXCEPTION=1
###< shopware/elasticsearch ###

###> shopware/storefront ###
STOREFRONT_PROXY_URL=https://localhost
SHOPWARE_HTTP_CACHE_ENABLED=1
SHOPWARE_HTTP_DEFAULT_TTL=7200
###< shopware/storefront ###

So sieht das Caddyfile aus

:80 {
    encode gzip zstd
    root * /var/www/html/public
    php_fastcgi php-lcmp3:9000 {
        trusted_proxies private_ranges
    }
    file_server
    header {
        -server
        -Link
        -X-Powered-By

        # disable FLoC tracking
        #Permissions-Policy interest-cohort=()

        # enable HSTS
        Strict-Transport-Security max-age=31536000;

        # disable clients from sniffing the media type
        X-Content-Type-Options nosniff

        # clickjacking protection
        X-Frame-Options DENY

       # keep referrer data off of HTTP connections
       Referrer-Policy no-referrer-when-downgrade
    }

    log
}

Ich habe echt keine Ahnung mehr, woran das jetzt noch liegen könnte.

Ich konnte es lösen, in dem ich diese index.php verwendet habe