zl程序教程

您现在的位置是:首页 >  系统

当前栏目

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

LinuxApache方法 环境 深入 介绍 虚拟主机 端口配置
2023-06-13 09:15:01 时间
默认情况下,linux上apache使用的
默认文档目录是:/var/www
默认端口是:80
如果想发布自己的一个系统资源目录,可以使用下面的方法,执行如下命令:
(1)添加监听端口
#cd/etc/apache2
#vimports.conf
文件添加:
NameVirtualHost*:8000
Listen8000
(2)配置虚拟目录
#cd/etc/apache2/sites-available
#cpdefaultdefault-me
#vimdefault-me
文件内容如下:
复制代码代码如下:

<VirtualHost*:8000>
   ServerAdminwebmaster@localhost
   DocumentRoot/wwwroot
   <Directory/>
OptionsFollowSymLinks
AllowOverrideNone
   </Directory>
   <Directory/wwwroot/>
OptionsIndexesFollowSymLinksMultiViews
AllowOverrideNone
Orderallow,deny
allowfromall
   </Directory>
   ErrorLog/var/log/apache2/error.log
   #Possiblevaluesinclude:debug,info,notice,warn,error,crit,
   #alert,emerg.
   LogLevelwarn
   CustomLog/var/log/apache2/access.logcombined
</VirtualHost>

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#VirtualHosts
#
#Ifyouwanttomaintainmultipledomains/hostnamesonyour
#machineyoucansetupVirtualHostcontainersforthem.Mostconfigurations
#useonlyname-basedvirtualhostssotheserverdoesn"tneedtoworryabout
#IPaddresses.Thisisindicatedbytheasterisksinthedirectivesbelow.
#
#Pleaseseethedocumentationat
#<URL:http://httpd.apache.org/docs/2.2/vhosts/>
#forfurtherdetailsbeforeyoutrytosetupvirtualhosts.
#
#Youmayusethecommandlineoption"-S"toverifyyourvirtualhost
#configuration.
#
#Usename-basedvirtualhosting.
#
NameVirtualHost*:81
NameVirtualHost*:82
NameVirtualHost*:83
NameVirtualHost*:84
NameVirtualHost*:85
NameVirtualHost*:86
#
#VirtualHostexample:
#AlmostanyApachedirectivemaygointoaVirtualHostcontainer.
#ThefirstVirtualHostsectionisusedforallrequeststhatdonot
#matchaServerNameorServerAliasinany<VirtualHost>block.
#
<VirtualHost*:81>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/www-nongye
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/www-nongye/errornongye.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:82>
<Directory"D:/AppServ/www-chinaec">
OptionsFollowSymLinks
#Denyfromall
Allowfromall
</Directory>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www-chinaec
ServerNamewww.dede.com
DirectoryIndexindex.phpindex.html
ErrorLogD:/AppServ/www-chinaec/errornongjiale.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:83>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/www-05110
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/www-05110/errornong05110.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:84>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/wordpress
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/wordpress/errornongwordpress.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:85>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/magento
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/magento/errormagento.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:86>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/magento1322
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/magento1322/errormagento1322.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:88>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/www-nongjiale
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/www-nongjiale/errornongjiale.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:80>
ServerAdminwebmaster@dummy-host2.x
DocumentRoot"C:/Apache2.2/docs/dummy-host2.x"
ServerNamedummy-host2.x
ErrorLog"logs/dummy-host2.x-error.log"
CustomLog"logs/dummy-host2.x-access.log"common
</VirtualHost>

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"
#
#ConfiguretheDocumentRoot
#
<Directory"/srv/www/htdocs">
#PossiblevaluesfortheOptionsdirectiveare"None","All",
#oranycombinationof:
#  IndexesIncludesFollowSymLinksSymLinksifOwnerMatchExecCGIMultiViews
#
#Notethat"MultiViews"mustbenamed*explicitly*---"OptionsAll"
#doesn"tgiveittoyou.
#
#TheOptionsdirectiveisbothcomplicatedandimportant. Pleasesee
#http://httpd.apache.org/docs-2.2/mod/core.html#options
#formoreinformation.
OptionsNone
#AllowOverridecontrolswhatdirectivesmaybeplacedin.htaccessfiles.
#Itcanbe"All","None",oranycombinationofthekeywords:
#  OptionsFileInfoAuthConfigLimit
AllowOverrideNone
#Controlswhocangetstufffromthisserver.
Orderallow,deny
Allowfromall
</Directory>

2、单域名多端口设置
复制代码代码如下:
<Directory"/srv/www/htdocs/bbs">
   OptionsNone
   AllowOverrideNone
   Orderallow,deny
   Allowfromall
</Directory>
<Directory"/srv/www/htdocs/">
   OptionsNone
   AllowOverrideNone
   Orderallow,deny
   Allowfromall
</Directory>
NameVirtualHost  *:80
NameVirtualHost  *:81
<VirtualHost*:80>
 DirectoryIndex index.htmlindex.php
 ServerName  "www.abc.com"
 DocumentRoot  "/srv/www/htdocs/" 
 </VirtualHost>
<VirtualHost*:81>
 DirectoryIndex  index.php
   ServerName  "www.abc.com:81"
 DocumentRoot  "/srv/www/htdocs/bbs/" 
 </VirtualHost>

3、多域名多端口设置
复制代码代码如下:
<Directory"/srv/www/htdocs/btc">
   OptionsNone
   AllowOverrideNone
   Orderallow,deny
   Allowfromall
</Directory>
<Directory"/srv/www/htdocs/bbs">
   OptionsNone
   AllowOverrideNone
   Orderallow,deny
   Allowfromall
</Directory>
<Directory"/srv/www/htdocs/">
   OptionsNone
   AllowOverrideNone
   Orderallow,deny
   Allowfromall
</Directory>
NameVirtualHost  *:80
NameVirtualHost  *:81
<VirtualHost*:80>
 DirectoryIndex index.htmlindex.php
 ServerName  "www.abc.com"
 DocumentRoot  "/srv/www/htdocs/" 
 </VirtualHost>
<VirtualHost*:80>
 DirectoryIndex index.htmlindex.php
 ServerName  "www.btc.com"
 DocumentRoot  "/srv/www/htdocs/btc" 
 </VirtualHost>
<VirtualHost*:81>
 DirectoryIndex  index.php
   ServerName  "www.abc.com:81"
 DocumentRoot  "/srv/www/htdocs/bbs/" 
 </VirtualHost>

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