linux环境apache多端口配置虚拟主机的方法深入介绍

教程大全 2026-01-08 08:19:11 浏览

默认情况下,linux上apache使用的默认文档目录是:/var/www默认端口是:80如果想发布自己的一个系统资源目录,可以使用下面的方法,执行如下命令: (1)添加监听端口 #cd /etc/apache2#vim ports.conf文件添加: NameVirtualHost *:8000Listen 8000 虚拟主机 (2)配置虚拟目录 #cd /etc/apache2/sites-available#cp default default-me#vim default-me 文件内容如下:

复制代码 代码如下:

ServerAdmin webmaster@localhostDocumentRoot /Options FollowSymLinksAllowOverride NoneOptions Indexes FollowSymLinks MultiViewsAllowOverride NoneOrder allow,denyallow from allErrorLog /var/log/apache2/error.log# Possible values include: debug, info, notice, warn, error, crit,# alert, emerg.LogLevel warnCustomLog /var/log/apache2/access.log combined

粗体部分是关键点。 (3)发布站点 # ln -s /etc/apache2/sites-available/default-me /etc/apache2/sites-enabled/001-default (4)重启服务 #/etc/init.d/apache2 restart (5)测试 如果能够正常访问就说明配置正确了。

复制代码 代码如下:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# 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# # 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 *:81NameVirtualHost *:82NameVirtualHost *:83NameVirtualHost *:84NameVirtualHost *:85NameVirtualHost *:86## 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 block.#ServerAdmin jsw7001@hotmail.comDocumentRoot D:/AppServ/www/www-nongyeServerName www.dede.comErrorLog D:/AppServ/www/www-nongye/errornongye.logCustomLog logs/dummy-host2.appservnetwork.com-access_log commonOptions FollowSymLinks#Deny from allAllow from allServerAdmin jsw7001@hotmail.comDocumentRoot D:/AppServ/www-chinaecServerName www.dede.comDirectoryIndex index.php index.htmlErrorLog D:/AppServ/www-chinaec/errornongjiale.logCustomLog logs/dummy-host2.appservnetwork.com-access_log commonServerAdmin jsw7001@hotmail.comDocumentRoot D:/AppServ/www/www-05110ServerName www.dede.comErrorLog D:/AppServ/www/www-05110/errornong05110.logCustomLog logs/dummy-host2.appservnetwork.com-access_log commonServerAdmin jsw7001@hotmail.comDocumentRoot D:/AppServ/www/woRDPressServerName www.dede.comErrorLog D:/AppServ/www/wordpress/errornongwordpress.logCustomLog logs/dummy-host2.appservnetwork.com-access_log commonServerAdmin jsw7001@hotmail.comDocumentRoot D:/AppServ/www/magentoServerName www.dede.comErrorLog D:/AppServ/www/magento/errormagento.logCustomLog logs/dummy-host2.appservnetwork.com-access_log commonServerAdmin jsw7001@hotmail.comDocumentRoot D:/AppServ/www/magento1322ServerName www.dede.comErrorLog D:/AppServ/www/magento1322/errormagento1322.logCustomLog logs/dummy-host2.appservnetwork.com-access_log commonServerAdmin jsw7001@hotmail.comDocumentRoot D:/AppServ/www/www-nongjialeServerName www.dede.comErrorLog D:/AppServ/www/www-nongjiale/errornongjiale.logCustomLog logs/dummy-host2.appservnetwork.com-access_log commonServerAdmin webmaster@dummy-host2.xDocumentRoot "C:/Apache2.2/docs/dummy-host2.x"ServerName dummy-host2.xErrorLog "logs/dummy-host2.x-error.log"CustomLog "logs/dummy-host2.x-access.log" common

1、单域名单端口设置 如:www.abc.com 默认用80访问特别说明,apache的配置默认都在安装目录下的conf目录里面或者是/etc/apache2不过一定要注意,listen.conf文件中端口监听是否开启如下图,表示已经开启80端口监听 直接默认1、单域名单端口设置 如:www.abc.com 默认用80访问特别说明,apache的配置默认都在安装目录下的conf目录里面或者是/etc/apache2不过一定要注意,listen.conf文件中端口监听是否开启如下图,表示已经开启80端口监听直接默认修改default-server.conf 这个配置最好简单 安装好了,之后,默认已经能够使用了,只是要把它修改成你需要的域名及访问路径罢了。给一个标准配置吧

复制代码 代码如下:

DocumentRoot "/srv/www/htdocs"## Configure the DocumentRoot## Possible values for the Options directive are "None", "All",# or any combination of:# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews## Note that "MultiViews" must be named *explicitly* --- "Options All"# doesn't give it to you.## The Options directive is both complicated and important. Please see#for more information.Options None# AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the Keywords:# Options FileInfo AuthConfig LimitAllowOverride None# Controls who can get stuff from this server.Order allow,denyAllow from all

2、单域名多端口设置

复制代码 代码如下:

Options NoneAllowOverride NoneOrder allow,denyAllow from allOptions NoneAllowOverride NoneOrder allow,denyAllow from allNameVirtualHost *:80NameVirtualHost *:81DirectoryIndex index.html index.phpServerName "www.abc.com "DocumentRoot "/srv/www/htdocs/"DirectoryIndex index.phpServerName "www.abc.com:81 "DocumentRoot "/srv/www/htdocs/bbs/"

3、多域名多端口设置

复制代码 代码如下:

Options NoneAllowOverride NoneOrder allow,denyAllow from allOptions NoneAllowOverride NoneOrder allow,denyAllow from allOptions NoneAllowOverride NoneOrder allow,denyAllow from allNameVirtualHost *:80NameVirtualHost *:81DirectoryIndex index.html index.phpServerName "www.abc.com "DocumentRoot "/srv/www/htdocs/"DirectoryIndex index.html index.phpServerName "www.btc.com "DocumentRoot "/srv/www/htdocs/btc"DirectoryIndex index.phpServerName "www.abc.com:81 "DocumentRoot "/srv/www/htdocs/bbs/"

需要注意的问题是,多端口监听,一定要注意listen.conf文件,是否开启了相应端口。

本文版权声明本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请联系本站客服,一经查实,本站将立刻删除。

发表评论

热门推荐