简体   繁体   中英

Laravel route() and url() functions return wrong subdomain

I'm creating test application with Laravel and Docker.

Docker容器

I have 3 Docker containers: one Apache which using ProxyPass selecting one of other two containers and two containers which have Laravel applications.

I have also extra lines in /etc/hosts

127.0.0.1        auth.pi
127.0.0.1        worker.pi

My main (green) Apache's conf file is

<VirtualHost *:80>
    ServerName auth.pi

    ProxyPass / http://auth:80/
</VirtualHost>

<VirtualHost *:80>
    ServerName worker.pi

    ProxyPass / http://worker:80/
</VirtualHost>

In red's `.env I have

APP_URL=http://auth.pi

But when I used url('/') or route(...) my domain is http://auth/ .

My red's Apache's conf

<VirtualHost *:80>
    ServerName auth.pi

    DocumentRoot /var/www/html/public

    <Directory "/var/www/html/public">
        AllowOverride all
    </Directory>

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

File docker-compose.yml contains:

services:
  apache:
    build: "./apache"
    container_name: "pi-apache"
    links:
      - "auth-apache:auth"
    ...
  auth-apache:
    build: "./applications/auth/apache"
    container_name: "pi-auth-apache"
    ...

What I do wrong? Why my red's Laravel app thinks that he is http://auth/ not http://auth.pi/ ?

In blue's app I have same configuration and same issue.

The problem is with green's conf

In VirtualHost section I must add

RequestHeader set Host "auth.pi"

ProxyPreserveHost On

Final VirtualHost for auth.pi

<VirtualHost *:80>
    ServerName auth.pi

    RequestHeader set Host "auth.pi"

    ProxyPreserveHost On

    ProxyPass / http://auth:80/
</VirtualHost>

I also added in docker-compose.yml

  auth-apache:
    build: "./applications/auth/apache"
    container_name: "pi-auth-apache"
    domainname: "pi"
    hostname: "auth"
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM