apache配置虚拟主机
apache虚拟主机
虚拟主机配置
基于IP的虚拟主机
基于名称的虚拟主机
基于IP地址的虚拟主机
通过对一台主机分配多个Ip地址,然后将Apache捆绑到不同的IP地址上,并对每一台虚拟主机提供惟一的IP地址来实现。
例如,一台Linux机器可能会有如下两个IP地址,分别绑定到不同的名称上。
192.168.0.1
192.168.0.2
基于IP地址的虚拟主机配置
<VirtualHost 192.168.0.1>
ServerName à在DNS或hosts中定义
ServerAdmin
DocumentRoot /www/abc
DirectoryIndex index.html index.htm index.php3
ErrorLog /var/log/httpd/abc_error_log
TransferLog /var/log/httpd/abc_access_log
</VirtualHost>
基于IP地址的虚拟主机配置
<VirtualHost 192.168.0.2>
ServerName 在DNS或hosts文件中定义
ServerAdmin
DocumentRoot /www/123
DirectoryIndex index.html index.htm index.php3
ErrorLog /var/log/httpd/123_error_log
TransferLog /var/log/httpd/123_access_log
</VirtualHost>
基于名称的虚拟主机
当遇到一个IP地址对应多个WebSite时,就需要设置基于名称的虚拟主机了。
要在虚拟主机的前面加上:
Name VirtualHost 192.168.0.1 n例如:
192.168.0.1
192.168.0.1
基于名称的虚拟主机配置
Name VirtualHost 192.168.0.1
<VirtualHost 192.168.0.1>
ServerName 在DNS或hosts文件中定义
ServerAdmin
DocumentRoot /www/abc
DirectoryIndex index.html index.htm index.php3
ErrorLog /var/log/httpd/abc_error_log
TransferLog /var/log/httpd/abc_access_log
</VirtualHost>
基于名称的虚拟主机配置
<VirtualHost 192.168.0.1>
ServerName 在DNS或hosts文件中定义
ServerAdmin
DocumentRoot /www/123
DirectoryIndex index.html index.htm index.php3
ErrorLog /var/log/httpd/123_error_log
TransferLog /var/log/httpd/123_access_log
</VirtualHost>
服务器安全设置
基于客户机名或IP地址限制
登录的安全认证
限制访问实例(1)
允许所有的访问
<direcotry /path>
Order allow,deny
Allow from all
</directory>
拒绝部分主机的访问
<direcotry /path>
Order allow,deny
Allow from all
Deny 192.168.0.11
</directory>
拒绝所有的主机访问
<direcotry /path>
Order deny,allow
Deny from all
</directory>
允许部分主机的访问
<direcotry /path>
Order deny,allow
Deny from all
Allow from 192.168.0.11
</directory>
登录的安全认证
可以设定整个站点、某个目录只能允许特定的用户访问,使得用户要输入账号名称和密码才可进入站点或目录。
加载主认证模块
LoadModule auth_module module/mod_auth.so
AddModule mod_auth.c
启动目录认证功能
<directory /path>
Allowoverride all à启用目录认证功能
</directory>
登录的安全认证
保护目录的配置文件指定
AccessFileName .htaccess
建立密码文件(此文件存放位置可自定义)
#htpasswd -c .htpasswd username
à创建帐号文件,并添加用户帐户和密码。
#htpasswd .htpasswd username
à添加新用户,且不覆盖原文件.
#htpasswd –m .htpasswd username
à修改已存在的用户密码
#chmod 704 .htpasswd
à设置任何用户有权限访问此文件
登录的安全认证
编辑.htaccess配置文件
此文件存放的目录即为要保护的目录,可以把这个文件放到发布根下就保护了站点的安全。
以下内容:
AuthUserFile /path/.htpasswd à密码文件的存放路径
Authname “Private Directory!” à提示框信息
Authtype basic
require valid-user
à表示可以访问此目录的用 户,”valid-user“为允许.htpasswd密码文件内定义的所有用户访问。也可指定某个用户,如”require user abc“
- 最新评论