Apache虚拟主机(vhost)配置教程

摘要:
目录“/home/www/sv1”>块。#</www/a“ServerNamea.comServerAliasww.a.comErrorLog”日志/a.com.log“CustomLog”日志/a.com.log“common<必需授权<

版本:Apache Version Apache/2.4.6 (Ubuntu)

系统: ubuntn12.04

在/etc/apache2/sites-enabled/

sudo cp 000-defaut.conf sv1.conf

sudo vim sv1.conf

<VirtualHost *:80>
  ServerName www.sv1.com
        ServerAdmin webmaster@localhost
        DocumentRoot /home/www/sv1
        DirectoryIndex index.html

</VirtualHost>

<Directory "/home/www/sv1">
  Options FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

sudo service apache2 restart

出现403错误,参考下面解决。  


使用apache来配置虚拟主机,在单一系统上运行多个网站。

现在很多linux主机使用apache作为web服务器的,大部分是基于这个原理来配置虚拟主机的。


下面就windows下以apache 2.4.3作为演示的一个教程。

这里只是简单的说明下,简述实现的原理

1.Apache的配置文件httpd.conf,找到Virtual hosts,进行如下修改保存。

# Virtual hosts#Include conf/extra/httpd-vhosts.conf去掉第2行的‘#’号,改为# Virtual hostsInclude conf/extra/httpd-vhosts.conf

这样就开启了extra文件夹下的httpd-vhosts.conf,以后修改虚拟主机只要在这个文件进行。


2.对httpd-vhosts.conf进行配置。

例如域名www.a.com和www.b.com

# Virtual Hosts## Required modules: mod_log_config# If you want to maintain multiple domains/hostnames on your# machine you can setup VirtualHost containers for them. Most configurations# use only name-based virtual hosts so the server doesn't need to worry about# IP addresses. This is indicated by the asterisks in the directives below.## Please see the documentation at # <URL:http://httpd.apache.org/docs/2.4/vhosts/># for further details before you try to setup virtual hosts.## You may use the command line option '-S' to verify your virtual host# configuration.## VirtualHost example:# Almost any Apache directive may go into a VirtualHost container.# The first VirtualHost section is used for all requests that do not# match a ServerName or ServerAlias in any <VirtualHost> block.#<VirtualHost*:80>ServerAdmin webmaster@a.com
    DocumentRoot"d:/www/a"ServerName a.com
    ServerAlias www.a.com
    ErrorLog"logs/a.com.log"CustomLog"logs/a.com.log" common
    <Directory"d:/www/a">Require all granted   
    </Directory> 
</VirtualHost><VirtualHost*:80>ServerAdmin webmaster@b.com
    DocumentRoot"d:/www/b"ServerName b.com
    ServerAlias www.b.com
    ErrorLog"logs/b.com.log"CustomLog"logs/b.com.log" common
    <Directory"d:/www/b">Require all granted   
    </Directory> 
</VirtualHost>

注意:apache 2.4以上版本中需要在目录下面添加 Require all granted,否则无论怎么访问都是403。

转载:http://www.myxzy.com/post-370.html

免责声明:文章转载自《Apache虚拟主机(vhost)配置教程》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇提高博客访问量的十四种方法360董事长周鸿伟在新员工入职培训上的讲话下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

vue的富文本编辑器使用,并且添加显示当前输入字数

下载: npm install vue-quill-editor --save main.js中引入 //富文本编辑器 import VueQuillEditor from 'vue-quill-editor'; import 'quill/dist/quill.core.css' import 'quill/dist/quill.snow.css'...

SpringBoot集成Druid实现数据源管理和监控

 1、添加Maven依赖 <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId>...

从html字符串中获取div内容---jquery

思考的问题: 怎么在一个网页的div中嵌套另外的网页(不使用inclue,iframe和frame,不使用他们的原因,include只能嵌套静态网页,iframe对网络爬虫影响,frame嵌套网页无法获取父级页面信息,不够灵活) 如果不想嵌套整个网页怎么办?(只是嵌套另外页面的部分内容) 回答(想法): 使用jquery的ajax函数或者load函数...

微服务中如何设计一个权限授权服务

基于角色的访问控制  (RBAC)    是将系统访问限制为授权用户的一种方法,是围绕角色和特权定义的与策略无关的访问控制机制,RBAC的组件使执行用户分配变得很简单。   在组织内部,将为各种职务创建角色。执行某些操作的权限已分配给特定角色。成员或职员(或其他系统用户)被分配了特定角色,并且通过这些角色分配获得执行特定系统功能所需的权限。由于未直接为用户...

List.Select按字符串选择属性

不知道大家有没有遇到这样的情况:List使用Lambda表达式的时候,想要选择项的某个属性列。 例如,选择编号ID: 1 var idList=list.Select(o=>o.ID).ToList(); 又,想要选择名称: 1 var nameList=list.Select(o=>o.Name).ToList(); 可否将其抽象呢?下面是我...

a 标签解决,新窗口打开跨域问题

<a href="https://xxxx.vip/home" rel="nofollow noreferrer" target="_blank"><img src="images/logo.png" alt="新窗口打开"></a> 重点在:rel属性...