文章目录:
- 1、如何配置 Apache 的虚拟主机
- 2、apache多站点虚拟主机,每个域名一个日志文件,你提问的这个问题我也遇到了,请问您是怎么解决的呢
- 3、如何在Debian 10上安装Apache并设置虚拟主机
- 4、apache设置多虚拟主机问题,请根据下面的要求具体解释哈,本人是菜鸟,太粗略了可能我不懂、、、
- 5、如何通过 apache VirtualHost 来设置多个虚拟主机
- 6、什么是虚拟主机,apache 虚拟主机
如何配置 Apache 的虚拟主机
1、基于ip地址的虚拟主机
复制代码代码如下:
Listen 80
VirtualHost 172.20.30.40
DocumentRoot /home/httpd/html1
ServerName
ErrorLog /usr/local/apache/logs/error1_log
CustomLog /usr/local/apache/logs/access1_log combined
/VirtualHost
VirtualHost 172.20.30.50
DocumentRoot /home/httpd/html2
ServerName
ErrorLog /usr/local/apache/logs/error2_log
CustomLog /usr/local/apache/logs/access2_log combined
/VirtualHost
2、基于IP 和多端口的虚拟主机配置
复制代码代码如下:
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080
VirtualHost 172.20.30.40:80
DocumentRoot /www/example1-80
ServerName
/VirtualHost
VirtualHost 172.20.30.40:8080
DocumentRoot /www/example1-8080
ServerName
/VirtualHost
VirtualHost 172.20.30.50:80
DocumentRoot /www/example2-80
ServerName
/VirtualHost
VirtualHost 172.20.30.50:8080
DocumentRoot /www/example2-8080
ServerName
/VirtualHost
3、单个IP 地址的服务器上基于域名的虚拟主机配置
复制代码代码如下:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
VirtualHost *:80
DocumentRoot /www/example1
ServerName
ServerAlias example1.com. *.example1.com
# Other directives here
/VirtualHost
VirtualHost *:80
DocumentRoot /www/example2
ServerName
# Other directives here
/VirtualHost
如果您感觉上面的文章还不够详细可以看下下面的文章:
实验目标:在apache实现基于域名的虚拟主机
实验用的XAMPP版本为1.7.7,内含apache版本为2.2.21
实验前准备:
1. 为了测试不同的域名,在Windows/System32/drivers/etc/下觅得hosts文件,在其中添加实验用的域名若干,如 –
复制代码代码如下:
127.0.0.1 test1.net
127.0.0.1 test2.net
如此,则在浏览器中输入该俩域名时,Windows将其解析为127.0.0.1本地地址。即,在浏览器中访问localhost, test1.net, test2.net均可访问XAMPP的欢迎页。
2. 在apache目录下建立目录,以放置您不同的网站。为保护XAMPP原有的htdocs中的欢迎页内容,实验另外建立了与htdocs平级的htdocs1目录,在其下建立了test1.net, test2.net两个子目录用以放置实验用的网站。如下 –
apache/htdocs1/test1.net – 放置test1.net网站内容
apache/htdocs1/test2.net – 放置test2.net网站内容
在这两个目录中各新建hello world一网页 index.html,内容 –
复制代码代码如下:
HTML
HEAD/HEAD
BODY
H1hello~, 这是[对应的网站名,用以区别].net/H1/BODY
/HTML
实验步骤:
1. 找到apache/conf/httpd.conf, 将其中的
ServerAdmin
ServerName
DocumentRoot
注释掉。
2. 在httpd.conf中,找到行
Include “conf/extra/httpd-vhosts.conf”
如被注释则解注。该文件记载了虚拟主机的参数。[以前虚拟主机参数是直接填写在httpd.conf中的,为了更好地组织文件,将其分离出去,类似于某些编程语言一样。因此httpd.conf中include它,即相当于把它的内容填在了httpd.conf中。]
3. 这个httpd-vhosts.conf文件格式基本如下 –
复制代码代码如下:
#blah-blah
NameVirtualHost *:80
#blah-blah
#blah-blah
VirtualHost *:80
ServerAdmin XXXXXXXX
DocumentRoot “XXXXXXXX”
ServerName XXXXXXX
ServerAlias XXXXXX
ErrorLog “logs/XXXXXX-error.log”
CustomLog “logs/XXXXXXX-error.log” combined
/VirtualHost
需要修改的,就是VirtualHost中的参数了。这个可以参见apache官方文档。根据实验域名,可以增加两个VirtualHost:
复制代码代码如下:
VirtualHost *:80
ServerAdmin adm@test1.net
DocumentRoot “C:/xampp/htdocs1/test1.net”
ServerName test1.net
ServerAlias
ErrorLog “logs/test1-error.log”
CustomLog “logs/test1-access.log” combined
Directory “C:/xampp/htdocs1/test1.net”
order allow,deny
allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin adm@test2.net
DocumentRoot “C:/xampp/htdocs1/test2.net”
ServerName test2.net
ServerAlias
ErrorLog “logs/test1-error.log”
CustomLog “logs/test1-access.log” combined
Directory “C:/xampp/htdocs1/test2.net”
order allow,deny
allow from all
/Directory
/VirtualHost
注意,如果不在各VirtualHost中定义Directory的可访问性,你将遇到的是Access Forbidden!就连原来的localhost也是。
4. 由于之前注释掉了httpd.conf中的ServerName, DocumentRoot等,为了仍然能以localhost访问原XAMPP欢迎页,就在增加一个VirtualHost,如下 –
复制代码代码如下:
VirtualHost *:80
ServerAdmin adm@localhost
DocumentRoot “C:/xampp/htdocs”
ServerName localhost
ErrorLog “logs/localhost-error.log”
CustomLog “logs/localhost-access.log” combined
Directory “C:/xampp/htdocs”
order allow,deny
allow from all
/Directory
/VirtualHost
为了避免出错,把它放置在第一个Virtualhost位置。
至此,apache基于域名的虚拟主机配置完成。可以通过访问XAMPP欢迎页,通过和访问各自的主页。
#
# Virtual Hosts
#
# 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:;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option ‘-S’ to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# 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 kongdaoxian@gmail.com
DocumentRoot “E:/skydao/apache2/htdocs”
ServerName localhost
ServerAlias
ErrorLog “logs/localhost-error.log”
CustomLog “logs/localhost-access.log” combined
Directory “E:/skydao/apache2/htdocs”
order allow,deny
allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin kongdaoxian@gmail.com
DocumentRoot “E:/skydao/apache2/htdocs/project1”
ServerName project1.com
ServerAlias
ErrorLog “logs/project1-error.log”
CustomLog “logs/project1-access.log” combined
Directory “E:/skydao/apache2/htdocs/project1”
order allow,deny
allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin kongdaoxian@gmail.com
DocumentRoot “E:/skydao/apache2/htdocs/zendTest/public”
ServerName zendTest.com
ServerAlias
DirectoryIndex index.php
Directory /
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin kongdaoxian@gmail.com
DocumentRoot “E:/skydao/apache2/htdocs/testRewrite”
ServerName testRewrite.com
ServerAlias
# DirectoryIndex index.php
Directory /
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin kongdaoxian@gmail.com
DocumentRoot “E:/skydao/apache2/htdocs/test”
ServerName test.com
ServerAlias
ErrorLog “logs/zendTest-error.log”
CustomLog “logs/zendTest-access.log” combined
Directory “E:/skydao/apache2/htdocs/test”
order allow,deny
allow from all
/Directory
/VirtualHost
apache多站点虚拟主机,每个域名一个日志文件,你提问的这个问题我也遇到了,请问您是怎么解决的呢
建议你参考下apache的配置文件,文件名是httpd.conf,具体路径的话每个操作系统不同的。你可以用whereis命令找一下。apache的管理最好用虚拟主机管理面板,要自己去开空间管理的话,需要看很多参考资料的。
如何在Debian 10上安装Apache并设置虚拟主机
Apache HTTP Server 是目前应用最多的 web server 服务软件之一,Apache提供了许多强大的功能,而且可以通过其他模块进行扩展。Apache HTTP Server是一个开源的跨平台的服务器软件,目前大部分网站都采用Apache作为网站HTTP服务器。
在本教程中,我们将向你介绍如何在Debian 10中安装Apache并配置虚拟主机。
首先你得有一台安装了Debian的服务器,这样便于你在上面进行演练操作。如果你没有可以考虑自己在虚拟机中安装一个Debian 10。当然,我也推荐您购买一台 阿里云VPS 或者 腾讯云VPS 虚拟主机,如果你更喜欢国外服务器,推荐你尝试 Vultr上的VPS ,注册即送$50美元体验,性价比非常高。
当然有主机了,为安全考虑不建议使用root账号,建议创建一个具有 sudo权限的用户 。
同时,你的Debian已经安装了PHP,如果没有安装可以参考「 如何在Debian 10安装PHP 」教程。
Apache的安装包在Debian的默认源中提供了,所以只需要执行安装命令即可安装。执行安装Apache命令之前我们需要先更新一下系统,命令如下:
安装完成后,apache将默认自动运行,我们通过以下命令查看apache服务状态。
输出命令类似如下:
开启防火墙可以加强服务器的安全性,我们通过防火墙只开放需要访问的端口。可以通过防火墙管理软件 ufw 或者 nftables 进行管理。
如果系统没有安装 ufw 或者 nftables ,可以通过如下命令直接安装。
UFW 如果需要开启 (HTTP)80 或者 (HTTPS)443 端口,可以通过执行如下命令开启:
nftables 如果需要开启 (HTTP)80 或者 (HTTPS)443 端口,可以通过执行如下命令开启:
这个更建议使用 UFW 作为防火墙管理软件,相对来说操作更简单。
Apache安装完成后,需要校验一下Apache是否正常工作。校验方法是打开浏览器,在地址栏中输入 ,如果能正常显示类似如下界面,说明Apache安装成功运行正常。
Apache安装完成后,默认的安装配置文件路径如下:
我们在 /var/www 目录中创建一个网站目录,例如 example.com 。默认情况,目录结构如下:
可以通过以下命令创建:
在该目录下我们创建一个 index.php 文件,文件内容如下:
首先,进入 /etc/apache2/sites-available 目录,创建配置文件 example.com.conf 文件,并在其中添加如下内容。
您可以根据需要命名虚拟主机配置文件,但是建议使用域名作为配置文件的名称。
要启用新的虚拟主机文件,请创建一个从虚拟主机文件到启用站点的目录的符号链接,该链接在启动过程中由Apache读取。
在Debian系统中,您可以使用名为 a2ensite 的帮助程序脚本来启用虚拟主机,命令如下:
当然你也可以选择手动创建符号链接,如下所示:
启用配置后,通过键入以下命令测试语法是否正确:
如果一切正常,会输出如下内容:
重启服务,使配置生效,命令如下:
在浏览器地址栏中输入 ,正常情况下你将看到如下输出:
至此,本教程交接完毕。
通过本教程,你将学会如何在Debian 10上安装Apache并设置虚拟主机,如果你有自己的的Debian 10主机不妨按照教程进行安装尝试,如果没有自己的Debian自己建议可以安装一台Debian10虚拟主机或者去 阿里云 或者 腾讯云 或者 Vultr 购买一台自己的VPS服务器。
apache设置多虚拟主机问题,请根据下面的要求具体解释哈,本人是菜鸟,太粗略了可能我不懂、、、
在 Apache 目录下的 conf 目录下的 extra 目录下有个 httpd-vhosts.conf 文件,打开,在最后插入如下代码:
#配置自己的虚拟主机
VirtualHost?*:80
????#网站目录,如果在www目录下的php目录,下面就填写F:/www/phpp
????DocumentRoot?”F:/www”?
????#域名
????ServerName?localhost
????#这里配置欢迎首页面
????DirectoryIndex?index.html?index.htm?index.php
????Directory?/
????Options?FollowSymLinks
????#不允许别人修改我们的页面
????AllowOverride?None
????#设置访问权限
????order?allow,deny
????Allow?from?all
????/Directory???
/VirtualHost
同样的方法配置3次,就是把ServerName后面的localhost改成你的a.a,b.b,c.c
如何通过 apache VirtualHost 来设置多个虚拟主机
你只要配置多个virtualhost就可以了,例如下面这样:
VirtualHost?*:80
????DocumentRoot?”/usr/local/www1″
????ServerName??a.test.com
????ErrorLog?”/var/log/httpd/www1-error_log”
????CustomLog?”/var/log/httpd/www1-access_log”?common
/VirtualHost
VirtualHost?*:80
????DocumentRoot?”/usr/local/www2″
????ServerName??b.test.com
????ErrorLog?”/var/log/httpd/www2-error_log”
????CustomLog?”/var/log/httpd/www2-access_log”?common
/VirtualHost
什么是虚拟主机,apache 虚拟主机
apache虚拟主机一般是php语言的网站程序搭建的一个环境,你需要apache虚拟主机吗?各大虚拟主机商都有的,建议你做好选用哪种全能型的虚拟主机,因为全能主机既支持asp程序,又支持php程序的网站,这会让你少去很多麻烦。
我的网站就是php程序的,当初选了个apache虚拟主机,也没感觉有什么优点,反而感觉单一,所以我还是建议你选择全能型的主机。选择国内好的虚拟主机服务商真的太少了,个人感觉好点的就是中国万网和荆轲网络、中国国万网比较适合企业建站,十分有保障,但是限制多。荆轲网络的价格合理,比较平民化。所以还是建议你选择荆轲网络。
荆轲网络的网址自己去百度搜索吧,这里不让发网址吗,悲催。
apache多虚拟主机的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于apache基于ip虚拟主机、apache多虚拟主机的信息别忘了在本站进行查找喔。
关于apache多虚拟主机(apache 虚拟主机)的内容来源于互联网引用、聚合而成,若侵权,请联系我们删除!九八云,优质云服务器提供商。