我在我的本地机器上安装了一个通配符子域(在Linux Mint 18.1上运行Apache 2.4.18)上运行我的应用程序(基于laravel 5.4)
所以,我已经为它设置了一个vhost(domain.app)和一个子域(sub.domain.app),我的apache vhost文件如下所示:
# This is for the primary domain (domain.app) <VirtualHost *:80> ServerName domain.app ServerAlias www.domain.app ServerAdmin webmaster@localhost DocumentRoot /var/www/html/test/domain.app/public <Directory /var/www/html/test/domain.app/public> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> <IfModule mod_dir.c> DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm </IfModule> </VirtualHost> # This is for the subdomain (sub.domain.app) <VirtualHost *:80> ServerName domain.app VirtualDocumentRoot /var/www/html/test/%0/public ServerAlias *.domain.app <Directory /var/www/html/test/sub.domain.app/public> <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> </Directory> </VirtualHost>
这适用于以下所有url:
但是,既然我想要一个通配符子域名,这意味着我不想在vhost中硬编码sub.domain.app,但想要类似anything.domain.app的东西,所以我试图replace
<Directory /var/www/html/test/sub.domain.app/public>
同
<Directory /var/www/html/test/%0/public>
我得到以下结果:
请有人可以帮我吗?
提前致谢
回答我自己的问题。
我终于find了解决办法。 我为通配符子域使用以下vhostconfiguration,并像魅力一样工作。
UseCanonicalName Off <VirtualHost *:80> ServerAdmin [email protected] ServerAlias *.domain.app VirtualDocumentRoot /var/www/html/test/%0/public DirectoryIndex index.php index.htm index.html <Directory /var/www/html/test/*.domain.app/public/> AllowOverride All </Directory> LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon CustomLog /var/log/apache2/vhosts-access.log vcommon ErrorLog /var/log/apache2/vhosts-error.log </VirtualHost>
希望这对面临类似问题的任何人都有用。
这是一个猜测,但我认为你需要在<Directory /var/www/html/test/sub.domain.app/public>指令中replacepath。