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


Posted in PHP onJune 09, 2013

默认情况下,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 index.html
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.html 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.html index.php
  ServerName   "www.abc.com "
  DocumentRoot   "/srv/www/htdocs/"  
  </VirtualHost>
<VirtualHost *:80>
  DirectoryIndex  index.html 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文件,是否开启了相应端口。
PHP 相关文章推荐
多文件上传的例子
Oct 09 PHP
如何实现给定日期的若干天以后的日期
Oct 09 PHP
PHP4 与 MySQL 数据库操作函数详解
Dec 06 PHP
写php分页时出现的Fatal error的解决方法
Apr 18 PHP
PHP IDE PHPStorm配置支持友好Laravel代码提示方法
May 12 PHP
关于PHP开发的9条建议
Jul 27 PHP
分享PHP源码批量抓取远程网页图片并保存到本地的实现方法
Dec 01 PHP
php快速排序原理与实现方法分析
May 26 PHP
全面了解PHP中的全局变量
Jun 17 PHP
PHP+原生态ajax实现的省市联动功能详解
Aug 15 PHP
PHP空值检测函数与方法汇总
Nov 19 PHP
PHP使用openssl扩展实现加解密方法示例
Feb 20 PHP
探讨PHP删除文件夹的三种方法
Jun 09 #PHP
如何用php获取文件名后缀
Jun 09 #PHP
深入php多态的实现详解
Jun 09 #PHP
深入PHP autoload机制的详解
Jun 09 #PHP
定义php常量的详解
Jun 09 #PHP
基于php冒泡排序算法的深入理解
Jun 09 #PHP
深入apache host的配置详解
Jun 09 #PHP
You might like
关于PHP session 存储方式的详细介绍
2013/06/25 PHP
什么情况下可以不写PHP的闭合标签“?&gt;”
2014/08/28 PHP
通用于ie和firefox的函数 GetCurrentStyle (obj, prop)
2006/12/27 Javascript
随鼠标上下滚动的jquery代码
2013/12/05 Javascript
JS常用函数使用指南
2014/11/23 Javascript
javascript无刷新评论实现方法
2015/05/13 Javascript
JS+CSS简单树形菜单实现方法
2015/09/12 Javascript
node.js+express制作网页计算器
2016/01/17 Javascript
jQuery模仿单选按钮选中效果
2016/06/24 Javascript
AngularJS中的DOM操作用法分析
2016/11/04 Javascript
微信小程序教程系列之视图层的条件渲染(10)
2017/04/19 Javascript
nodejs6下使用koa2框架实例
2017/05/18 NodeJs
jQuery开源组件BootstrapValidator使用详解
2017/06/29 jQuery
vue.js简单配置axios的方法详解
2017/12/13 Javascript
优雅地使用loading(推荐)
2019/04/20 Javascript
JS实现音量控制拖动
2020/01/15 Javascript
[00:08]DOTA2勇士令状等级奖励“天外飞星”
2019/05/24 DOTA
python正常时间和unix时间戳相互转换的方法
2015/04/23 Python
Python3写入文件常用方法实例分析
2015/05/22 Python
Python中使用haystack实现django全文检索搜索引擎功能
2017/08/26 Python
python版本的仿windows计划任务工具
2018/04/30 Python
Pycharm在创建py文件时,自动添加文件头注释的实例
2018/05/07 Python
python中协程实现TCP连接的实例分析
2018/10/14 Python
selenium处理元素定位点击无效问题
2019/06/12 Python
PyQt5响应回车事件的方法
2019/06/25 Python
python函数局部变量、全局变量、递归知识点总结
2019/11/15 Python
Flask之pipenv虚拟环境的实现
2019/11/26 Python
Python IDLE或shell中切换路径的操作
2020/03/09 Python
Python连接Hadoop数据中遇到的各种坑(汇总)
2020/04/14 Python
Python执行时间的几种计算方法
2020/07/31 Python
HTML5 Canvas中绘制椭圆的4种方法
2015/04/24 HTML / CSS
Made in Design德国:设计师家具、灯具和装饰
2019/10/31 全球购物
研发工程师岗位职责
2014/04/28 职场文书
员工开除通知书
2015/04/25 职场文书
导游词之上饶龟峰
2019/10/25 职场文书
Python docx库删除复制paragraph及行高设置图片插入示例
2022/07/23 Python