Apache虛擬主機(vhost)配置教程

版本:Apache Version Apache/2.4.6 (Ubuntu)html

系統: ubuntn12.04linux

在/etc/apache2/sites-enabled/web

sudo cp 000-defaut.conf sv1.confapache

sudo vim sv1.confvim

<VirtualHost *:80>
  ServerName www.sv1.com
        ServerAdmin webmaster@localhost
        DocumentRoot /home/www/sv1
        DirectoryIndex index.htmlwindows

</VirtualHost>服務器

<Directory "/home/www/sv1">
  Options FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

dom

sudo service apache2 restart ide

出現403錯誤,參考下面解決。   post


 

使用apache來配置虛擬主機,在單一系統上運行多個網站。

如今不少linux主機使用apache做爲web服務器的,大部分是基於這個原理來配置虛擬主機的。


下面就windows下以apache 2.4.3做爲演示的一個教程。

這裏只是簡單的說明下,簡述實現的原理

1.Apache的配置文件httpd.conf,找到Virtual hosts,進行以下修改保存。

# Virtual hosts#Include conf/extra/httpd-vhosts.conf去掉第2行的‘#’號,改成# Virtual hostsInclude conf/extra/httpd-vhosts.conf

這樣就開啓了extra文件夾下的httpd-vhosts.conf,之後修改虛擬主機只要在這個文件進行。


2.對httpd-vhosts.conf進行配置。

例如域名www.a.com和www.b.com

# Virtual Hosts## Required modules: mod_log_config# If you want to maintain multiple domains/hostnames on your# machine you can setup VirtualHost containers for them. Most configurations# use only name-based virtual hosts so the server doesn't need to worry about# IP addresses. This is indicated by the asterisks in the directives below.## Please see the documentation at # <URL:http://httpd.apache.org/docs/2.4/vhosts/># for further details before you try to setup virtual hosts.## You may use the command line option '-S' to verify your virtual host# configuration.## VirtualHost example:# Almost any Apache directive may go into a VirtualHost container.# The first VirtualHost section is used for all requests that do not# match a ServerName or ServerAlias in any <VirtualHost> block.#<VirtualHost*:80>ServerAdmin webmaster@a.com
    DocumentRoot"d:/www/a"ServerName a.com
    ServerAlias www.a.com
    ErrorLog"logs/a.com.log"CustomLog"logs/a.com.log" common
    <Directory"d:/www/a">Require all granted   
    </Directory> 
</VirtualHost><VirtualHost*:80>ServerAdmin webmaster@b.com
    DocumentRoot"d:/www/b"ServerName b.com
    ServerAlias www.b.com
    ErrorLog"logs/b.com.log"CustomLog"logs/b.com.log" common
    <Directory"d:/www/b">Require all granted   
    </Directory> 
</VirtualHost>

注意:apache 2.4以上版本中須要在目錄下面添加 Require all granted,不然不管怎麼訪問都是403。

轉載:http://www.myxzy.com/post-370.html

相關文章
相關標籤/搜索