Apache、Nginx和Tomcat之虚拟主机配置

简介:

在主配置添加如下,配置完主配置文件都必须重启或重新加载才生效

1、Apache基于域名虚拟主机

1
2
3
4
5
6
7
8
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虚拟目录:

1
2
3
4
5
6
7
8
vi  /etc/httpd/conf/httpd .conf
Alias /虚拟目录名  "/myweb"
<Directory  "/myweb" >
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
< /Directory >

3、基于HTTP用户身份认证访问

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 >
1
2
3
4
5
创建用户及密码,此处密码与用户的系统密码无关
htpasswd -c  /etc/httpd/ . passwd  user1
New password:
Re- type  new password:
Adding password  for  user user

4、Nginx虚拟主机

1
2
3
4
5
6
7
8
9
10
11
12
13
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虚拟主机

1
2
3
4
5
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 >


目录
相关文章
|
2月前
|
Java 应用服务中间件 Apache
简介Nginx,Tomcat和 Apache
简介Nginx,Tomcat和 Apache
简介Nginx,Tomcat和 Apache
|
10天前
|
运维 前端开发 Java
Tomcat详解(八)——Tomcat与Nginx实现动静分离
Tomcat详解(八)——Tomcat与Nginx实现动静分离
18 6
|
负载均衡 安全 Java
Nginx & Tomcat - 区别
Nginx & Tomcat - 区别
80 0
|
负载均衡 安全 Java
|
Web App开发 负载均衡 网络协议
一文看懂Tomcat、Nginx和Apache的区别
一文看懂Tomcat、Nginx和Apache的区别
301 0
一文看懂Tomcat、Nginx和Apache的区别
|
开发框架 负载均衡 Java
服务器之Apache和Tomcat和Nginx的理解和对比
服务器之Apache和Tomcat和Nginx的理解和对比
382 0
|
Web App开发 Java 应用服务中间件
NGINX+TOMCAT实现反向代理
环境说明 NGINX: 192.168.10.10 TOMCAT: 192.168.10.11 NGINX部分 [root@nginx ~]# wget http://nginx.org/download/nginx-1.
1193 0
|
Web App开发 JavaScript 前端开发

推荐镜像

更多