热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

本篇文章是对linux环境apache多端口配置虚拟主机的方法进行了详细的分析介绍,需要的朋友参考下
默认情况下,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
文件内容如下:

代码如下:


8000 >
ServerAdmin webmaster@localhost
DocumentRoot /wwwroot

Options FollowSymLinks
AllowOverride None

wwwroot/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

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


粗体部分是关键点。
(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
#
# 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 block.
#

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



Options FollowSymLinks
#Deny from all
Allow from all

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


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


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


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


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


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


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


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
# 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


2、单域名多端口设置

代码如下:



Options None
AllowOverride None
Order allow,deny
Allow from all


Options None
AllowOverride None
Order allow,deny
Allow from all

NameVirtualHost *:80
NameVirtualHost *:81

DirectoryIndex index.html index.php
ServerName "www.abc.com "
DocumentRoot "/srv/www/htdocs/"


DirectoryIndex index.php
ServerName "www.abc.com:81 "
DocumentRoot "/srv/www/htdocs/bbs/"


3、多域名多端口设置

代码如下:



Options None
AllowOverride None
Order allow,deny
Allow from all


Options None
AllowOverride None
Order allow,deny
Allow from all


Options None
AllowOverride None
Order allow,deny
Allow from all

NameVirtualHost *:80
NameVirtualHost *:81

DirectoryIndex index.html index.php
ServerName "www.abc.com "
DocumentRoot "/srv/www/htdocs/"


DirectoryIndex index.html index.php
ServerName "www.btc.com "
DocumentRoot "/srv/www/htdocs/btc"


DirectoryIndex index.php
ServerName "www.abc.com:81 "
DocumentRoot "/srv/www/htdocs/bbs/"


需要注意的问题是,多端口监听,一定要注意listen.conf文件,是否开启了相应端口。
推荐阅读
  • mac php错误日志配置方法及错误级别修改
    本文介绍了在mac环境下配置php错误日志的方法,包括修改php.ini文件和httpd.conf文件的操作步骤。同时还介绍了如何修改错误级别,以及相应的错误级别参考链接。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 本文介绍了Linux系统中正则表达式的基础知识,包括正则表达式的简介、字符分类、普通字符和元字符的区别,以及在学习过程中需要注意的事项。同时提醒读者要注意正则表达式与通配符的区别,并给出了使用正则表达式时的一些建议。本文适合初学者了解Linux系统中的正则表达式,并提供了学习的参考资料。 ... [详细]
  • Ubuntu 9.04中安装谷歌Chromium浏览器及使用体验[图文]
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • CentOS 7部署KVM虚拟化环境之一架构介绍
    本文介绍了CentOS 7部署KVM虚拟化环境的架构,详细解释了虚拟化技术的概念和原理,包括全虚拟化和半虚拟化。同时介绍了虚拟机的概念和虚拟化软件的作用。 ... [详细]
  • 一句话解决高并发的核心原则
    本文介绍了解决高并发的核心原则,即将用户访问请求尽量往前推,避免访问CDN、静态服务器、动态服务器、数据库和存储,从而实现高性能、高并发、高可扩展的网站架构。同时提到了Google的成功案例,以及适用于千万级别PV站和亿级PV网站的架构层次。 ... [详细]
  • 目录浏览漏洞与目录遍历漏洞的危害及修复方法
    本文讨论了目录浏览漏洞与目录遍历漏洞的危害,包括网站结构暴露、隐秘文件访问等。同时介绍了检测方法,如使用漏洞扫描器和搜索关键词。最后提供了针对常见中间件的修复方式,包括关闭目录浏览功能。对于保护网站安全具有一定的参考价值。 ... [详细]
  • 本文介绍了5个基本Linux命令行工具的现代化替代品,包括du、top和ncdu。这些替代品在功能上进行了改进,提高了可用性,并且适用于现代化系统。其中,ncdu是du的替代品,它提供了与du类似的结果,但在一个基于curses的交互式界面中,重点关注占用磁盘空间较多的目录。 ... [详细]
author-avatar
书友36296361
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有