在主配置添加如下,配置完主配置文件都必须重启或重新加载才生效
1、Apache基于域名虚拟主机
vi
/etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot /var/www/test.com
ServerName www.test.com
ServerAlias test1.com
ErrorLog "/var/www/logs/test.com-error_log"
CustomLog "/var/www/logs/test.com-access_log"common
</VirtualHost>
2、Apache虚拟目录:
vi
/etc/httpd/conf/httpd.conf
Alias /虚拟目录名 "/myweb"
<Directory "/myweb">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
3、基于HTTP用户身份认证访问
vi
/etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot /var/www/test.com
ServerName www.test.com
ServerAlias test1.com
ErrorLog "/var/www/logs/test.com-error_log"
CustomLog "/var/www/logs/test.com-access_log"common
<Directory "/var/www/html">
AuthType Basic#定义使用认证方式,basic或digest
AuthName"Please input Password"
#保护领域的提示信息
AuthUserFile/etc/httpd/.passwd#指定认证口令文件的位置
#Require user user1 #授权给指定的一个或多个用户,也可以是一个组:Require group 组名
Require valid-user#授权给认证口令文件的所有用户
</Directory>
</VirtualHost>
创建用户及密码,此处密码与用户的系统密码无关
htpasswd -c /etc/httpd/.passwduser1
New password:
Re-typenew password:
Adding password for
user user
4、Nginx虚拟主机
vi
/usr/local/nginx/conf/nginx.conf #在http{}添加包含虚拟主机配置
include /usr/local/nginx/vhost/*.conf;
vi
/usr/local/nginx/conf/vhost/test.com.conf #创建虚拟主机配置文件
server {
listen 80;
server_name www.test1.com test1.com;#设置域名
charset utf8; #设置网页默认字符集
access_log logs/test1.com.log main;#访问日志
location / {
root /usr/local/nginx/html/test1.com;#网页根目录位置
index index.html index.htm; #网站首页
}
}
5、Tomcat虚拟主机
vi
tomcat/conf/server.xml #添加站点
<Host name="www.test.com"appBase="/web"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"xmlNamespaceAware="false">
<Context path=""docBase="/"
debug="0"
/> #虚拟目录名、虚拟目录路径
</Host>