900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Apache基于域名 端口 IP的虚拟主机配置(Centos 6.5)

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

时间:2021-04-12 02:44:07

相关推荐

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

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

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

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

创建环境:

[root@bqh-119 extra]# mkdir /var/html/{blog,bbs} -p[root@bqh-119 extra]# touch /var/html/{blog,bbs}/index.html[root@bqh-119 extra]# tree /var/html//var/html/├── bbs│ └── index.html└── blog└── index.html2 directories, 2 files[root@bqh-119 extra]# for name in blog bbs;do echo "http://$" >/var/html/$name/index.html;done[root@bqh-119 extra]# for name in blog bbs;do cat /var/html/$name/index.html;done

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

[root@bqh-119 extra]# vim httpd-vhosts.conf1 #2 # Virtual Hosts3 #4 # If you want to maintain multiple domains/hostnames on your5 # machine you can setup VirtualHost containers for them. Most configurations6 # use only name-based virtual hosts so the server doesn't need to worry about7 # IP addresses. This is indicated by the asterisks in the directives below.8 #9 # Please see the documentation at 10 # <URL:/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 host14 # configuration.15 16 #17 # Use name-based virtual hosting.18 #19 NameVirtualHost *:8020 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 not25 # match a ServerName or ServerAlias in any <VirtualHost> block.26 #27 <VirtualHost *:80>28ServerAdmin 1147076062@29DocumentRoot "/var/html/blog"30ServerName 31ServerAlias 32ErrorLog "logs/blog-error_log"33CustomLog "logs/blog-access_log" common34 </VirtualHost>35 36 <VirtualHost *:80>37ServerAdmin 1147076062@38DocumentRoot "/var/html/bbs"39ServerName 40ServerAlias 41ErrorLog "logs/bbs-error_log"42CustomLog "logs/bbs-access_log" common43 /VirtualHost>

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

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

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

[root@bqh-119 extra]# ../../bin/apachectl -thttpd: apr_sockaddr_info_get() failed for bqh-119httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerNameSyntax OK[root@bqh-119 extra]# ../../bin/apachectl gracefulhttpd: apr_sockaddr_info_get() failed for bqh-119httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

配置一下hosts解析:

[root@bqh-119 extra]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.0.119

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

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

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

解决方法:

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

17 <Directory "/var/html">18Options FollowSymLinks19AllowOverride None20Order allow,deny21Allow from all22 </Directory>

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

[root@bqh-119 conf]# vim httpd.conf[root@bqh-119 conf]# ../bin/apachectl -thttpd: apr_sockaddr_info_get() failed for bqh-119httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerNameSyntax OK[root@bqh-119 conf]# ../bin/apachectl gracefulhttpd: apr_sockaddr_info_get() failed for bqh-119httpd: 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修改如下:

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

[root@bqh-119 conf]# ../bin/apachectl -thttpd: apr_sockaddr_info_get() failed for bqh-119httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerNameSyntax OK[root@bqh-119 conf]# ../bin/apachectl gracefulhttpd: apr_sockaddr_info_get() failed for bqh-119httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName[root@bqh-119 conf]# netstat -lntup|egrep "80|90"tcp 00 :::80 :::* LISTEN1343/httpdtcp 00 :::90 :::* LISTEN1343/httpd

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

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

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

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

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

①添加别名IP

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

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

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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。