Apache2.2\conf\httpd.conf与Apache2.2\conf\extra\httpd-vhosts.conf两个文件的操作
?
httpd.conf下apache默认是80端口,找到 Listen 80就可以修改,想要增加新的端口直接添加一个Listen 8080之类的就OK了,如
Listen 8080
Listen 8081,如果没有为不同的端口指定目录,它们都访问DocumentRoot
修改目录:
apache默认访问的是安装目录下的htdocs,默认打开就出来It Works!,它由DocumentRoot定义如:
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
如果你想将换个目录可以直接DocumentRoot "x:/workspace/project/www"
?
授权:修改目录后,还要给目录设置访问的权限,如果不给权限是不能访问的。如:
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
? ? Options Indexes FollowSymLinks
? ? AllowOverride None
? ? Order allow,deny
? ? Allow from all
</Directory>
?
配置多目录:
当前项目有两个分支,一个在trunck/www下面,另一个在branch/www下面,于是想localhost:8080访问trunck/www,localhost:8081访问branch/www
?
首先要开启虚拟主机:找到httpd.conf中#Include conf/extra/httpd-vhosts.conf,去掉前面的#号
接着配置不同url对应的目录,找到extra/httpd-vhosts.conf
修改默认端口80与8080,并添加一个8081的端口
NameVirtualHost *:8080
?
NameVirtualHost *:8081
设置目录:
<VirtualHost *:8080>
? ? ServerAdmin webmaster@dummy-host.smiky
? ? DocumentRoot "D:/work/trunk/www"
? ? ServerName dummy-host.smiky
? ? ServerAlias www.dummy-host.smiky
? ? ErrorLog "logs/dummy-host.smiky.log"
? ? CustomLog "logs/dummy-host.smiky-access.log" common
</VirtualHost>
<VirtualHost *:8081>
? ? ServerAdmin webmaster@dummy-host.smiky
? ? DocumentRoot "D:/work/branch/www"
? ? ServerName dummy-host.smiky
? ? ServerAlias www.dummy-host.smiky
? ? ErrorLog "logs/dummy-host.smiky.log"
? ? CustomLog "logs/dummy-host.smiky-access.log" common
</VirtualHost>
配好后,再回到httpd.conf中为这两个目录添加权限
<Directory "D:/work/trunk/www">
? ? Options Indexes FollowSymLinks
? ? AllowOverride None
? ? Order allow,deny
? ? Allow from all
</Directory>
<Directory "D:/work/branch/www">
? ? Options Indexes FollowSymLinks
? ? AllowOverride None
? ? Order allow,deny
? ? Allow from all
</Directory>
?