Home > php教程 > php手册 > apache配置多站点,apache配置站点

apache配置多站点,apache配置站点

WBOY
Release: 2016-06-13 09:03:54
Original
1150 people have browsed it

apache配置多站点,apache配置站点

在httpd.conf文件中,有如下配置(注:舍去httpd.conf文件的注释内容)

Listen 80
ServerName localhost
<directory></directory>
    AllowOverride none
    Require all denied



DocumentRoot "E:"
<directory>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</directory>
Copy after login



(测试之前最好清理一下浏览器缓存),那么在浏览器中输入http://localhost/Workshop/Apache/ 便可以访问E:/Workshop/Apache下的所有文件,注意此处的根目录是E:,但是上面的那个Directory设置了权限所以无法访问E盘下面的所有内容,如果将上面的那个Directoy更改为:


<directory></directory>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
Copy after login



那么便可以从浏览器中访问E盘的所有东西,当在浏览器中输入localhost的时候,浏览器将会显示E盘根目录下的所有内容,并且可以访问。为了安全,我们通常不这么做,因此经常的设置方法是下面这样的配置:


Listen 80
ServerName localhost
<directory></directory>
    AllowOverride none
    Require all denied



DocumentRoot "E:/Workshop/Apache"
<directory>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</directory>
Copy after login



通过浏览器只允许访问特定目录,此处也就是E:/Workshop/Apache目录下的所有内容。当然对于第二个Dir,可以设置E:/Workshop/Apache下不同文件夹的访问权限。


最后说一下虚拟主机的设置,请按照以下格式设置(放在httpd.conf文件末尾即可):


如下所示,需要首先设置监听端口,然后是NameVirtualHost指定主机地址以及端口,接下来就是对VirtualHost进行设置了,其中包括SeverName也就是主机名以及文档根目录,注意对于本地开发时,将ServerName设置为localhost或者127.0.0.1即可,其中的文档根目录与目录设置一样即可,或者你也可以在文档根目录中为不同的文件夹设置不同的访问权限。其中的×号代表监听所有访问设置端口的虚拟主机。

Listen 81
NameVirtualHost *:81
<virtualhost>
    ServerName 127.0.0.1
    DocumentRoot "C:/Users/Administrator/php/webroot1"
    <directory>
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</directory>
</virtualhost>


Listen 82
NameVirtualHost ×:82
<virtualhost>
    ServerName 127.0.0.1
    DocumentRoot "C:/Users/Administrator/php/webroot2"
    <directory>
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</directory>
</virtualhost>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template