关掉主配置文件中的网页设置
#DocumentRoot "/usr/local/apache2//htdocs"
#<Directory "/usr/local/apache2//htdocs">
# Options Indexes FollowSymLinks
# AllowOverride None
# <RequireAll>
# Require all granted
# Require not ip 192.168.193.1
# </RequireAll>
#</Directory>
开启虚拟主机选项
Include etc//extra/httpd-vhosts.conf
基于IP的虚拟主机:
一台服务器,多个IP,搭建多个网站
vim etc/extra/httpd-vhosts.conf
<VirtualHost 192.168.193.2>
# ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/baidu"
ServerName www.baidu.com
# ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
<Directory "/usr/local/apache2/htdocs/baidu">
require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.193.4>
# ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/xdl"
ServerName www.xdl.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
<Directory "/usr/local/apache2/htdocs/xdl">
require all granted
</Directory>
</VirtualHost>
基于端口的虚拟主机
一台服务器,一个ip,搭建多个网站,每个网络使用不同端口访问
vim etc/extra/httpd-vhosts.conf
#Listen 80
Listen 8080
<VirtualHost 192.168.193.2:80>
# ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/baidu"
ServerName www.baidu.com
"etc/extra/httpd-vhosts.conf" 53L, 1717C 23,1 顶端
DocumentRoot "/usr/local/apache2/htdocs/baidu"
ServerName www.baidu.com
# ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
<Directory "/usr/local/apache2/htdocs/baidu">
require all granted
options Indexes
Allowoverride None
</Directory>
</VirtualHost>
<VirtualHost 192.168.193.2:8080>
# ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/xdl"
ServerName www.xdl.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
<Directory "/usr/local/apache2/htdocs/xdl">
require all granted
options Indexes
Allowoverride None
</Directory>
</VirtualHost>
基于域名的虚拟主机
一台服务器,一个ip,搭建多个网站,每个网站使用不同域名访问
<VirtualHost *:80>
# ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/baidu"
ServerName www.baidu.com
<sr/local/apache2/etc/extra/httpd-vhosts.conf" 53L, 1690C 25,1 顶端
DocumentRoot "/usr/local/apache2/htdocs/baidu"
ServerName www.baidu.com
# ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
<Directory "/usr/local/apache2/htdocs/baidu">
require all granted
options Indexes
Allowoverride None
</Directory>
</VirtualHost>
<VirtualHost *:80>
# ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/xdl"
ServerName www.qq.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
<Directory "/usr/local/apache2/htdocs/xdl">
require all granted
options Indexes
Allowoverride None
</Directory>
</VirtualHost>
将域名www.baidu.com、www.qq.com在DNS服务器中解析
为每个用户分别添加不同的个人主页:
启用主配置文件的访问设置
LoadModule userdir_module modules/mod_userdir.so
Include etc//extra/httpd-userdir.conf
#vim /usr/local/apache2/etc/extra/httpd-userdir.con
UserDir public_html
#
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory "/home/*/public_html">
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
默认设置就可以不用修改
用户家目录中建立 public_html 文件,并修改用户家目录的权限有读权限
drwx-----x. 4 lf lf 4096 5月 29 19:46 lf
drwx-----x. 4 fengyunfan fengyunfan 4096 5月 29 19:48 fengyunfan