简体   繁体   English

Laravel route()和url()函数返回错误的子域

[英]Laravel route() and url() functions return wrong subdomain

I'm creating test application with Laravel and Docker. 我正在使用Laravel和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. 我有3个Docker容器:一个Apache,使用ProxyPass选择其他两个容器之一,以及两个具有Laravel应用程序的容器。

I have also extra lines in /etc/hosts 我在/etc/hosts也有多余的行

127.0.0.1        auth.pi
127.0.0.1        worker.pi

My main (green) Apache's conf file is 我的主要(绿色)Apache的conf文件是

<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 在红色的.env中,我有

APP_URL=http://auth.pi

But when I used url('/') or route(...) my domain is http://auth/ . 但是当我使用url('/')route(...)我的域名是http://auth/

My red's Apache's conf 我的红色是Apache的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: 文件docker-compose.yml包含:

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/ ? 为什么我的红色Laravel应用认为他是http://auth/而不是http://auth.pi/

In blue's app I have same configuration and same issue. 在blue的应用程序中,我具有相同的配置和相同的问题。

The problem is with green's conf 问题是格林的conf

In VirtualHost section I must add VirtualHost部分,我必须添加

RequestHeader set Host "auth.pi"

ProxyPreserveHost On

Final VirtualHost for auth.pi auth.pi最终VirtualHost

<VirtualHost *:80>
    ServerName auth.pi

    RequestHeader set Host "auth.pi"

    ProxyPreserveHost On

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

I also added in docker-compose.yml 我还添加了docker-compose.yml

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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