我在
下有很多网络项目[/var/www/personal]$ ls
project1 project2 app1 app2 hello index.php
我希望通过访问来访问这些项目:
project.dev.me
project2.dev.me
app1.dev.me
app2.dev.me
hello.dev.me
当我访问dev.me
时,它会转到/var/www/personal/index.php
到目前为止,我已将此添加到我的主机中:
dev.me 127.0.0.1
并在apache config中启用了vhost_alias mod, 这是我的虚拟主机配置:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName dev.me
ServerAlias *.dev.me
VirtualDocumentRoot /var/www/personal/%1
<Directory /var/www/personal/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/dev.me.error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/dev.me.access.log combined
</VirtualHost>
但它不起作用。 我有两个问题:
1)我可以在不将每个子域添加到主机文件中的情况下使用吗?
2)如果我将每个子域添加到我的hosts文件中,我可以使子域工作,但是我该怎么做才能使dev.me指向index.php?
答案 0 :(得分:0)
没有运行本地DNS(例如Avahi或Bind9),除了在/etc/hosts
中定义单个主机名之外别无他法。引用具有虚拟主机配置的目录可能是最可编写脚本的(为了自动添加/删除vhost)...例如:
/ etc / hosts(没有可用的通配符)
127.0.0.1 localhost dev.me
127.0.0.1 project01.dev.me project02.dev.me
/etc/httpd/conf/httpd.conf中
IncludeOptional /etc/httpd/conf.vhosts.d/*.conf
/etc/httpd/conf.vhosts.d/10-project01.conf
<VirtualHost *:80>
ServerName project01.dev.me
ServerAdmin root@localhost
DocumentRoot /var/www/project01
<Directory /var/www/project01/>
</Directory>
</VirtualHost>
/etc/httpd/conf.vhosts.d/10-project02.conf
<VirtualHost *:80>
ServerName project02.dev.me
ServerAdmin root@localhost
DocumentRoot /var/www/project02
<Directory /var/www/project02/>
</Directory>
</VirtualHost>
/etc/httpd/conf.vhosts.d/99-localhost.conf
<VirtualHost *:80>
ServerName localhost
ServerAlias *
ServerAdmin root@localhost
DocumentRoot /var/www/localhost
<Directory /var/www/localhost/>
</Directory>
</VirtualHost>
配置文件检查显示:
httpd -S
ServerAlias *仅适用于最终的全能(例如,显示一些项目经理UI):
port 80 namevhost localhost (/etc/httpd/conf.vhosts.d/99-localhost.conf:3)
wild alias *