请google一下apache和虚拟主机,
例如以下内容
配置虚拟主机
1.
在 sites-available/ 目录下创建新的文件填写此虚拟主机的配置指令
2.
使用 a2ensite 命令启用虚拟主机; 使用 a2dissite 命令停用虚拟主机
例如要创建一个基于端口的虚拟主机,要执行如下的步骤:
S1. 修改 /etc/apache2/ports.conf 文件添加一个新的监听端口
Listen 80
Listen 8080
/etc/apache2/ports.conf
S2. 在 sites-available/ 目录下创建新的文件 192.168.0.222-8080,添加如下的配置
<VirtualHost 192.168.0.222:8080>
ServerAdmin [email protected]
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
DocumentRoot /home/www/192.168.0.222-8080
<Directory /home/www/192.168.0.222-8080/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
</VirtualHost>
/etc/apache2/sites-available/192.168.0.222:8080
S3. 创建 /home/www 目录和 index 文件
sudo mkdir -p /home/www/192.168.0.222-8080
sudo touch /home/www/192.168.0.222-8080/index.php
S4. 使用 a2ensite 命令启用虚拟主机
sudo a2ensite 192.168.0.222-8080
S5. 重新启动 Apache
sudo /etc/init.d/apache2 restart
以下是一个实例
ports.conf 文件内容 例
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz
#如果开多个虚拟主机,所有的NameVirtualHost,都应该设置为以下一样,或不写
#不然会错 如 *:3008 has no VirtualHosts
NameVirtualHost *:80
#每增加一个端口,就增加一条 Listen 端口
Listen 3008
Listen 8080
<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
在sites-available增加一个文件,访问时输入 http://IP:8080/labelhttp/,这样,非网页文件便可下载
内容如下(内容仿default)
只改动了三个地方
Alias /labelhttp /home/ftp/users/labelhttp
DocumentRoot /home/ftp/users/labelhttp
<Directory /home/ftp/users/labelhttp/>
详细其他内容如下
Alias /labelhttp /home/ftp/users/labelhttpServerAdmin [email protected]
DocumentRoot /home/ftp/users/labelhttp
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/ftp/users/labelhttp/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>