Apache基于域名、端口、IP的虚拟主机配置(Centos 6.5)

虚拟主机:部署多个站点,每个站点,希望用不同的域名和站点目录,或者是不同的端口,不同的ip,需要虚拟主机功能。一句话,一个http服务要配置多个站点,就需要虚拟主机。

虚拟主机分类:基于域名、基于端口、基于ip;所谓的基于**,就是靠**来区分不同的站点,支持各种混合,N多个虚拟主机。

基于端口的虚拟主机配置如下:

创建环境:

站点目录 域名
/var/html/blog blog.bqh123.com
/var/html/bbs bbs.bqh123.com
[[email protected]119 extra]# mkdir /var/html/{blog,bbs} -p
[[email protected]-119 extra]# touch /var/html/{blog,bbs}/index.html
[[email protected]-119 extra]# tree /var/html/
/var/html/
├── bbs
│   └── index.html
└── blog
    └── index.html

2 directories, 2 files
[[email protected]-119 extra]# for name in blog bbs;do echo "http://$name.bqh123.com" >/var/html/$name/index.html;done
[[email protected]-119 extra]# for name in blog bbs;do  cat /var/html/$name/index.html;done
http://blog.bqh123.com
http://bbs.bqh123.com

配置虚拟主机配置文件:httpd-vhosts.conf

[[email protected]119 extra]# vim httpd-vhosts.conf

  1 #
  2 # Virtual Hosts
  3 #
  4 # If you want to maintain multiple domains/hostnames on your
  5 # machine you can setup VirtualHost containers for them. Most configurations
  6 # use only name-based virtual hosts so the server doesn‘t need to worry about
  7 # IP addresses. This is indicated by the asterisks in the directives below.
  8 #
  9 # Please see the documentation at
 10 # <URL:http://httpd.apache.org/docs/2.2/vhosts/>
 11 # for further details before you try to setup virtual hosts.
 12 #
 13 # You may use the command line option ‘-S‘ to verify your virtual host
 14 # configuration.
 15
 16 #
 17 # Use name-based virtual hosting.
 18 #
 19 NameVirtualHost *:80
 20
 21 #
 22 # VirtualHost example:
 23 # Almost any Apache directive may go into a VirtualHost container.
 24 # The first VirtualHost section is used for all requests that do not
 25 # match a ServerName or ServerAlias in any <VirtualHost> block.
 26 #
 27 <VirtualHost *:80>
 28     ServerAdmin 1147076062@qq.com
 29     DocumentRoot "/var/html/blog"
 30     ServerName blog.bqh123.com
 31     ServerAlias bg.bqh123.com
 32     ErrorLog "logs/blog-error_log"
 33     CustomLog "logs/blog-access_log" common
 34 </VirtualHost>
 35
 36 <VirtualHost *:80>
 37     ServerAdmin 1147076062@qq.com
 38     DocumentRoot "/var/html/bbs"
 39     ServerName bbs.bqh123.com
 40     ServerAlias bs.bqh123.com
 41     ErrorLog "logs/bbs-error_log"
 42     CustomLog "logs/bbs-access_log" common
 43 /VirtualHost>

 在主配置文件(httpd.conf)里激活生效:

  • Include conf/extra/httpd-vhosts.conf
  • Include conf/extra/httpd-mpm.conf

检测配置文件语法错误并刷新配置:

[[email protected]119 extra]# ../../bin/apachectl -t
httpd: apr_sockaddr_info_get() failed for bqh-119
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[[email protected]-119 extra]# ../../bin/apachectl graceful
httpd: apr_sockaddr_info_get() failed for bqh-119
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

配置一下hosts解析:

[[email protected]119 extra]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.0.119 blog.bqh123.com bbs.bqh123.com

windows系统,在“C:\Windows\System32\drivers\etc”下的hosts中配置一下域名解析:

----------------------------------------------------------------------------------

用cur或客户端浏览器测试一下:

解决方法:

在主配置文件(httpd.conf)追加一下内容:

 17 <Directory "/var/html">
 18     Options  FollowSymLinks
 19     AllowOverride None
 20     Order allow,deny
 21     Allow from all
 22 </Directory>

检测配置文件语法错误,刷新配置,从新启动:

[[email protected]119 conf]# vim httpd.conf
[[email protected]-119 conf]# ../bin/apachectl -t
httpd: apr_sockaddr_info_get() failed for bqh-119
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[[email protected]-119 conf]# ../bin/apachectl graceful
httpd: apr_sockaddr_info_get() failed for bqh-119
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

用cur或客户端浏览器测试一下:

---------------------------------------------------------------------------------

ok,Apache基于域名的虚拟主机配置及测试完成。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

基于端口的虚拟主机配置如下:

①在主配置文件httpd.conf里配置监听新增端口:

②在虚拟机配置文件httpd-vhosts.conf修改如下:

③检测配置文件语法错误,刷新配置,从新启动:

[[email protected]119 conf]# ../bin/apachectl -t
httpd: apr_sockaddr_info_get() failed for bqh-119
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[[email protected]-119 conf]# ../bin/apachectl graceful
httpd: apr_sockaddr_info_get() failed for bqh-119
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
[[email protected]119 conf]# netstat -lntup|egrep "80|90"
tcp        0      0 :::80                       :::*                        LISTEN      1343/httpd
tcp        0      0 :::90                       :::*                        LISTEN      1343/httpd 

④用cur或客户端浏览器测试一下:

注:如果不加端口访问,默认以ip的形式解析访问。

ok,Apache基于端口的虚拟主机配置及测试完成。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

基于IP的虚拟主机配置如下:

①添加别名IP

②在虚拟机配置文件httpd-vhosts.conf修改如下:

③检测配置文件语法错误,刷新配置,从新启动:

④用cur或客户端浏览器测试一下:

ok,Apache基于IP的虚拟主机配置及测试完成

原文地址:https://www.cnblogs.com/su-root/p/11185264.html

时间: 2024-11-03 21:08:29

Apache基于域名、端口、IP的虚拟主机配置(Centos 6.5)的相关文章

nginx基本域名 端口 IP 的虚拟主机

基于域名 ##nginx并发连接数 processes 乘 connection ## worker_processes 服务进程数,一般和cpu 核心一致即可 worker_processes 1; events { ##一个worker同时服务数量 worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout

CentOS 7运维管理笔记(6)----Apache 基于 IP 的虚拟主机配置

Apache 配置虚拟主机支持3种方式:基于IP的虚拟主机配置,基于端口的虚拟主机配置,基于域名的虚拟主机配置.本篇随笔记录自己基于IP的虚拟主机配置. 如果同一台服务器有多个IP,可以使用基于IP的虚拟主机配置,将不同的服务绑定在不同的IP上. (1)绑定IP: 在虚拟机中搭建的CentOS 7 服务器的IP被自己设置为了静态IP 192.168.1.210,现在使用ifconfig在同一个网络接口上绑定192.168.1.211~213这三个IP: ifconfig eth0:1 192.1

Nginx总结(二)基于ip的虚拟主机配置

前面讲了如何安装配置Nginx,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要说的是Nginx如何配置虚拟主机. 1. 什么是虚拟主机 虚拟主机是一种特殊的软硬件技术,它可以将网络上的每一台计算机分成多个虚拟主机,每个虚拟主机可以独立对外提供www服务,这样就可以实现一台主机对外提供多个web服务,每个虚拟主机之间是独立的,互不影响的. 如下图: 通过nginx可以实现虚拟主机的

源码编译安装LAMP环境及配置基于域名访问的多虚拟主机

实验环境及软件版本: CentOS版本: 6.6(2.6.32.-504.el6.x86_64) apache版本: apache2.2.27 mysql版本:  Mysql-5.6.23 php版本:    php-5.3.27 一.关闭防火墙:service iptables stop chkconfig iptables off 二.关闭selinux: sed -i 's/SELINUX=disabled/SELINUX=enforcing/g' /etc/selinux/config

源码编译安装LNMP环境及配置基于域名访问的多虚拟主机

实验环境及软件版本: CentOS版本: 6.6(2.6.32.-504.el6.x86_64) apache版本: nginx-1.6.2 mysql版本:  Mysql-5.6.23 php版本:    php-5.6.3 一.关闭防火墙:service iptables stop chkconfig iptables off 二.关闭selinux: sed -i 's/SELINUX=disabled/SELINUX=enforcing/g' /etc/selinux/config in

nginx基于IP的虚拟主机配置

1.       增加IP 2.       [[email protected] ~]# ifconfigeth0:1 192.168.47.137 netmask 255.255.255.0 up 3.       [[email protected] ~]# ifconfigeth0:2 192.168.47.136 netmask 255.255.255.0 up 4.       [[email protected] ~]# ifconfigeth0:0 192.168.47.135

mac 下 xampp 多域名 多站点 多虚拟主机 配置

前言:最近用mac工作了,需要搭建个调试前段程序的站点,选了xampp,需求是能同时运行多个站点,多个域名,目录自定义,网上找了好多资料,都感觉有些不符合心意,且复制文确实很多,甚至有些没实践过的在乱写,不能达到我的需求,因此自己配置成功后,写个博文,一来纪录下防止忘记,二来希望对有些同学有帮助. 注明:该博文的终端用的是zsh,因此界面上和bash有些许不同,但命令基本上都相同,可参考把 Mac 上的 bash 换成 zsh xampp,下载地址:http://www.apachefriend

lamp centos虚拟主机配置

1.基于不同端口的虚拟主机配置 [[email protected]~]# vi /etc/httpd/conf/httpd.conf Listen 80      #设置监听不同的虚拟主机需要使用的端口 Listen 8080 Listen 8088 <Virtualhost*:80>                      #三个不同端口的主机 ServerName www.80.com DocumentRoot /var/www/html/80 </Virtualhost>

Nginx配置基于多域名、端口、IP的虚拟主机

原文:https://www.cnblogs.com/ssgeek/p/9220922.html ------------------------------- 1.类型介绍 1.1 基于域名的虚拟主机 所谓基于域名的虚拟主机,意思就是通过不同的域名区分不同的虚拟主机,基于域名的虚拟主机是企业应用最广的虚拟主机类型,几乎所有对外提供服务的网站使用的都是基于域名的主机,例如www.test1.com www.test2.com等 1.2 基于端口的虚拟主机 同理,所谓基于端口的虚拟主机,意思就是通