当前位置: 移动技术网 > IT编程>开发语言>PHP > linux环境apache多端口配置虚拟主机的方法深入介绍

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

2019年04月09日  | 移动技术网IT编程  | 我要评论
默认情况下,linux上apache使用的
默认文档目录是:/var/www
默认端口是:80
如果想发布自己的一个系统资源目录,可以使用下面的方法,执行如下命令:
(1)添加监听端口
#cd /etc/apache2
#vim ports.conf
文件添加:
namevirtualhost *:8000
listen 8000
(2)配置虚拟目录
#cd /etc/apache2/sites-available
#cp default default-me
#vim default-me
文件内容如下:
复制代码 代码如下:

<virtualhost *:8000 >
    serveradmin webmaster@localhost
    documentroot /wwwroot
    <directory / >
options followsymlinks
allowoverride none
    </directory>
    <directory /wwwroot/ >
options indexes followsymlinks multiviews
allowoverride none
order allow,deny
allow from all
    </directory>
    errorlog /var/log/apache2/error.log
    # possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    loglevel warn
    customlog /var/log/apache2/access.log combined
</virtualhost>

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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:http://httpd.apache.org/docs/2.2/vhosts/ >
# 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 *:81
namevirtualhost *:82
namevirtualhost *:83
namevirtualhost *:84
namevirtualhost *:85
namevirtualhost *: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 <virtualhost> block.
#
<virtualhost *:81>
serveradmin jsw7001@hotmail.com
documentroot d:/appserv/www/www-nongye
servername www.dede.com
errorlog d:/appserv/www/www-nongye/errornongye.log
customlog logs/dummy-host2.appservnetwork.com-access_log common
</virtualhost>
<virtualhost *:82>
<directory "d:/appserv/www-chinaec" >
options followsymlinks
#deny from all
allow from all
</directory>
serveradmin jsw7001@hotmail.com
documentroot d:/appserv/www-chinaec
servername www.dede.com
directoryindex index.php
errorlog d:/appserv/www-chinaec/errornongjiale.log
customlog logs/dummy-host2.appservnetwork.com-access_log common
</virtualhost>
<virtualhost *:83>
serveradmin jsw7001@hotmail.com
documentroot d:/appserv/www/www-05110
servername www.dede.com
errorlog d:/appserv/www/www-05110/errornong05110.log
customlog logs/dummy-host2.appservnetwork.com-access_log common
</virtualhost>
<virtualhost *:84>
serveradmin jsw7001@hotmail.com
documentroot d:/appserv/www/wordpress
servername www.dede.com
errorlog d:/appserv/www/wordpress/errornongwordpress.log
customlog logs/dummy-host2.appservnetwork.com-access_log common
</virtualhost>
<virtualhost *:85>
serveradmin jsw7001@hotmail.com
documentroot d:/appserv/www/magento
servername www.dede.com
errorlog d:/appserv/www/magento/errormagento.log
customlog logs/dummy-host2.appservnetwork.com-access_log common
</virtualhost>
<virtualhost *:86>
serveradmin jsw7001@hotmail.com
documentroot d:/appserv/www/magento1322
servername www.dede.com
errorlog d:/appserv/www/magento1322/errormagento1322.log
customlog logs/dummy-host2.appservnetwork.com-access_log common
</virtualhost>
<virtualhost *:88>
serveradmin jsw7001@hotmail.com
documentroot d:/appserv/www/www-nongjiale
servername www.dede.com
errorlog d:/appserv/www/www-nongjiale/errornongjiale.log
customlog logs/dummy-host2.appservnetwork.com-access_log common
</virtualhost>
<virtualhost *:80>
serveradmin webmaster@dummy-host2.x
documentroot "c:/apache2.2/docs/dummy-host2.x"
servername dummy-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"
#
# configure the documentroot
#
<directory "/srv/www/htdocs">
# 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
# http://httpd.apache.org/docs-2.2/mod/core.html#options
# 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 limit
allowoverride none
# controls who can get stuff from this server.
order allow,deny
allow from all
</directory>

2、单域名多端口设置
复制代码 代码如下:

<directory "/srv/www/htdocs/bbs">
    options none
    allowoverride none
    order allow,deny
    allow from all
</directory>
<directory "/srv/www/htdocs/">
    options none
    allowoverride none
    order allow,deny
    allow from all
</directory>
namevirtualhost   *:80
namevirtualhost   *:81
<virtualhost *:80>
  directoryindex  index.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">
    options none
    allowoverride none
    order allow,deny
    allow from all
</directory>
<directory "/srv/www/htdocs/bbs">
    options none
    allowoverride none
    order allow,deny
    allow from all
</directory>
<directory "/srv/www/htdocs/">
    options none
    allowoverride none
    order allow,deny
    allow from all
</directory>
namevirtualhost   *:80
namevirtualhost   *:81
<virtualhost *:80>
  directoryindex  index.php
  servername   "www.abc.com "
  documentroot   "/srv/www/htdocs/" 
  </virtualhost>
<virtualhost *:80>
  directoryindex  index.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文件,是否开启了相应端口。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网