当前位置: 动力学知识库 > 问答 > 编程问答 >

webserver - Create a dynamic vhost in apache

问题描述:

All my vhost are the same way and I dont want to create for every project a new one so I thought there is maybe a way to match the project_name environment based on the domain which call the webserver.

My current Vhost:

<VirtualHost *:80>

DocumentRoot "/Users/l91/Development/<project_name>/web"

ServerName <project_name>.<environment>

<Directory "/Users/l91/Development/<project_name>/web">

Options Indexes FollowSymlinks

SetEnv SYMFONY_ENV <environment>

AllowOverride All

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

网友答案:

It sounds more like you're looking for aliases or rewrites, rather than a virtual host. You can likely use rewrite rules to find them dynamically.

网友答案:

Did get it to work with this configuration:

NameVirtualHost *:80

<Directory "/Users/l91/Development/Websites">
    Options Indexes FollowSymlinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

UseCanonicalName Off
VirtualDocumentRoot /Users/l91/Development/Websites/%0/web

SetEnvIf X-SYMFONY_ENV "^prod$" SYMFONY_ENV=prod
SetEnvIf X-SYMFONY_ENV "^stage$" SYMFONY_ENV=stage
SetEnvIf SYMFONY_ENV "^$" SYMFONY_ENV=dev

and use of the following plugin to change ENVs by setting a header: https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj

分享给朋友:
您可能感兴趣的文章:
随机阅读: