聘我网

新概念招聘3.0

让Apache在多个端口接受访问

vote up0vote downstar

有时候我们会有这种需求:

当访问http://localhost时显示文件夹A下面的内容, 而访问http://localhost:888时显示B下面的内容。

如何让Apache实现这种功能呢?

其实很简单(以下皆为操作httpd.conf):

首先 添加Listen 888,让Apache也监听888这个端口

其次,为888端口设置一个VirtualHost

<VirtualHost *:888>
    ServerName  localhost
    DocumentRoot "D:/wamp/news"
</VirtualHost>

最后,设置其目录的访问权限:

<Directory "D:/wamp/news/">
    Options FollowSymLinks
    Order Deny,Allow
    Allow from 127.0.0.1
</Directory>

更新

如果要在一个端口设置多个virtualhost:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName  localhost
DocumentRoot "...
<Directory "...">
...
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName  symfony
DocumentRoot "D:\wamp\sfp\web"
<Directory "D:\wamp\sfp\web">
...
</Directory>
</VirtualHost>
 

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.