Apache-不重启完成添加或更改域名
这两天开始学习Linux环境下配置Apache服务器,结合现在行业实况,我特地注意学习了虚拟主机的配置方法,我买的书上讲的方法是在httpd.conf文件中添加VirtualHost来实现的,经过实践也成功了,但是这个方法需要在配置后重启httpd服务才能生效,下面我就介绍一种无需重启Apache即可更改域名、网站根目录的方法。
注:本方法来源于网上,本人还没有青紫实践。
第一步
打开apache的配置文件httpd.conf,去掉LoadModule rewrite_module modules/mod_rewrite.so前面的#号。
第二步
在配置文件尾部加上
RewriteEngine on
RewriteMap lowercase int:tolower
#定义映像文件
RewriteMap vhost txt:/apache/vhost/vhost.map
#处理变名
RewriteCond % !^/icons/
RewriteCond % !^/cgi-bin/
RewriteCond $} ^(.+)$
这里做基于文件的重新映射
RewriteCond $ ^(/.*)$
RewriteRule ^/(.*)$ %1/
RewriteCond % ^/cgi-bin/
RewriteCond $} ^(.+)$
RewriteCond $ ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/
注意:vhost.map文件是域名和空间映像的文件,格式如下
www.abc.com /vhostusr/www.abc.com
(你不会连/vhostuser/www.abc.com目录也没建吧,会报错的哟)
第三步
保存配置文件,重启apache,以后建立域名时,只要在vhost.map文件里添加相应记录,并建立相应文件夹就OK了~~~
其实这个可以用php脚本来完成的,很简单的~~呵呵~~~,就像现在的虚拟主机提供商一样,允许用户自行绑定域名。
注意啊:php_admin_value open_basedir “path",这个选项要配好啊~~新手如果不懂的,就不要动这个了
======================================================
贴一个简单的vhost.map文件的操作代码。。。随意写的,根据你自己的实际情况稍加修改就可以实现在线管理域名绑定了。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="top" href="index.cgi" title="" />
<link rel="search" href="search.php" title="" />
<link rel="help" href="faq.php" title="" />
<link rel="author" href="memberlist.php" title="" />
<title>注册 - youname.sun126.com</title>
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
scrollbar-face-color: #DEE3E7;
scrollbar-highlight-color: #FFFFFF;
scrollbar-shadow-color: #DEE3E7;
scrollbar-3dlight-color: #D1D7DC;
scrollbar-arrow-color: #;
scrollbar-track-color: #EFEFEF;
scrollbar-darkshadow-color: #98AAB1;
}
font,th,td,p { font-family: 'song',Verdana }
a:link,a:active,a:visited { color : #; }
a:hover { text-decoration: underline; color : #DD6900; }
hr { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
.bodyline { background-color: #FFFFFF; border: 1px #98AAB1 solid; }
.forumline { background-color: #000000; border: 0px #9898ba solid; }
td.row1 { background-color: #f0f3fa; }
td.row2 { background-color: #fafbfc; }
td.row3 { background-color: #D1D7DC; }
td.rowpic {
background-color: #D1D9E2;
background-repeat: repeat-y;
}
th {
color: #333333; font-size: 12px; font-weight : bold;
background-color: #9898BA; height: 25px;
td.cat,td.catHead,td.catSides,td.catLeft,td.catRight,td.catBottom {
background-color:#d1d9e2; border: #9898ba; border-style: solid; height: 28px;
}
td.cat,td.catHead,td.catBottom {
height: 29px;
border-width: 0px 0px 0px 0px;
}
th.thHead,th.thSides,th.thTop,th.thLeft,th.thRight,th.thBottom,th.thCornerL,th.thCornerR {
font-weight: bold; border: #FFFFFF; border-style: solid; height: 28px;
}
td.row3Right,td.spaceRow {
background-color: #D1D7DC; border: #9898ba; border-style: solid;
}
th.thHead,td.catHead { font-size: 13px; border-width: 1px 1px 0px 1px; }
th.thSides,td.catSides,td.spaceRow { border-width: 0px 1px 0px 1px; }
th.thRight,td.catRight,td.row3Right { border-width: 0px 1px 0px 0px; }
th.thLeft,td.catLeft { border-width: 0px 0px 0px 1px; }
th.thBottom,td.catBottom { border-width: 0px 1px 1px 1px; }
th.thTop { border-width: 1px 0px 0px 0px; }
th.thCornerL { border-width: 1px 0px 0px 1px; }
th.thCornerR { border-width: 1px 1px 0px 0px; }
.maintitle {
font-weight: bold; font-size: 22px; font-family: "'song',Verdana",'song',Verdana;
text-decoration: none; line-height : 120%; color : #;
}
.gen { font-size : 13px; }
.genmed { font-size : 12px; }
.gensmall { font-size : 12px; }
.gen,.genmed,.gensmall { color : #; }
a.gen,a.genmed,a.gensmall { color: #; text-decoration: none; }
a.gen:hover,a.genmed:hover,a.gensmall:hover { color: #DD6900; text-decoration: underline; }
/* The register, login, search etc links at the top of the page */
.mainmenu { font-size : 12px; color : # }
a.mainmenu { text-decoration: none; color : #; }
a.mainmenu:hover{ text-decoration: underline; color : #DD6900; }
/* Forum category titles */
.cattitle { font-weight: bold; font-size: 13px ; letter-spacing: 1px; color : #}
a.cattitle { text-decoration: none; color : #; }
a.cattitle:hover{ text-decoration: underline; }
/* Forum title: Text and link to the forums used in: index.cgi */
.forumlink { font-weight: bold; font-size: 13px; color : #; }
a.forumlink { text-decoration: none; color : #; }
a.forumlink:hover{ text-decoration: underline; color : #DD6900; }
/* Used for the navigation text, (Page 1,2,3 etc) and the navigation bar when in a forum */
.nav { font-weight: bold; font-size: 12px; color : #;}
a.nav { text-decoration: none; color : #; }
a.nav:hover { text-decoration: underline; }
/* titles for the topics: could specify viewed link colour too */
.topictitle {font-size: 12px; color : #; }
h1,h2 { font-weight: bold; font-size: 12px; color : #; }
a.topictitle:link { text-decoration: none; color : #; }
a.topictitle:visited { text-decoration: none; color : #333333; }
a.topictitle:hover { text-decoration: underline; color : #DD6900; }
/* Name of poster in viewmsg.php and viewtopic.php and other places */
.name { font-size : 12px; color : #;}
/* Location, number of posts, post date etc */
.postdetails { font-size : 12px; color : #; }
/* The content of the posts (body of text) */
.postbody { font-size : 13px; line-height: 18px}
a.postlink:link { text-decoration: none; color : # }
a.postlink:visited { text-decoration: none; color : #333333; }
a.postlink:hover { text-decoration: underline; color : #DD6900}
/* Quote & Code blocks */
.code {
font-family: 'song',Verdana; font-size: 12px; color: #006600;
background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
.quote {
font-family: 'song',Verdana; font-size: 12px; color: #444444; line-height: 125%;
background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
/* Copyright and bottom info */
.copyright { font-size: 12px; font-family: 'song',Verdana; color: #444444; letter-spacing: -1px;}
a.copyright { color: #444444; text-decoration: none;}
a.copyright:hover { color: #; text-decoration: underline;}
/* Form elements */
input,textarea, select {
color : #;
font: normal 12px 'song',Verdana;
border-color : #;
}
/* The text input fields background colour */
input.post, textarea.post, select {
background-color : #FFFFFF;
}
input { text-indent : 2px; }
/* The buttons used for bbCode styling in message post */
input.button {
background-color : #EFEFEF;
color : #;
font-size: 12px; font-family: 'song',Verdana;
}
/* The main submit button option */
input.mainoption {
background-color : #FAFAFA;
font-weight : bold;
}
/* None-bold submit button */
input.liteoption {
background-color : #FAFAFA;
font-weight : normal;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#" link="#" vlink="#333333" />
<a name="top"></a>
<!--栏目条-->
<style type=text/css>
A.title1:link
A.title1:visited
A.title1:active
A.title1:hover
A.title2:link
A.title2:visited
A.title2:active
A.title2:hover
</style>
<?php
if (empty($HTTP_POST_VARS[reg])) {
?>
<form action="<?=$PHP_SELF?>" enctype="multipart/form-data" method="post">
<table border="0" cellpadding="3" cellspacing="1" width="95%" align=center class="forumline">
<tr>
<th class="thHead" colspan="2" height="25" valign="middle"> <a href=http://www.sun126.com>精彩奇讯科技虚拟主机自助申请系统</a> 请填写注册信息</th>
</tr>
<tr>
<td class="row2" colspan="2"><span class="gensmall">请输入在本服务器新增的域名:</span></td>
</tr>
<tr>
<td class="row1" width="20%"><span class="gen">域名名称: http://</span></td>
<td class="row2"><input type="text" class="post" style="width:100px" name="domain" size="10" maxlength="25"><span class="gen"><font color=red>.sun126.com</font></span></td>
</tr>
<tr>
<td class="row1" colspan="2" align="center" height="28">
<input type="hidden" name="dateformat" value="Y-m-d H:m" maxlength="14" class="post" />
<input type="hidden" name="reg" value="1" /><input type="submit" name="submit" value="发送" class="mainoption" /> <input type="reset" value="重设" name="reset" class="liteoption" /></td>
</tr>
</table>
</form>
</center>
</body>
</html>
<?php }
?>
<?php
if ($HTTP_POST_VARS[reg]) {
for($i=0;$i<9;$i++){
$char1=chr(rand(97,122));
$chara.=$char1;
}
$domain = $HTTP_POST_VARS[domain] . ".sun126.com /" . $HTTP_POST_VARS[domain];
// 检查并创建目录开始*******************************
if (is_dir('d:/vhostuser/user_'.$chara.'_'.$HTTP_POST_VARS[domain])) {
$domain = "http://" . $domain;
echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"95%\" align=center class=\"forumline\"><tr>
<td class=\"row2\" colspan=\"2\"><span class=\"gensmall\">此域名已经使用,请更换~~<a href=$PHP_SELF>返回</a></span></td>
</tr>
<tr>
<td class=\"row2\" colspan=\"2\"><span class=\"gensmall\"> <a href=$domain target=_blank><FONT COLOR=BLUE><u>点击查看已开空间</u></FONT></a></span></td>
</tr></table>";
exit;
} else {
mkdir('d:/vhostuser/user_'.$chara.'_'.$HTTP_POST_VARS[domain]);
}
$HTTP_POST_VARS[reg] = "0";
$domain = "http://" . $domain;
echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"95%\" align=center class=\"forumline\"><tr>
<td class=\"row2\" colspan=\"2\"><span class=\"gensmall\">空间开设成空!~~<a href=$PHP_SELF>返回</a></span><span class=\"gensmall\"> <a href=$domain target=_blank><FONT COLOR=BLUE>点击查看已开空间</FONT></a> <a href=http://www.sun126.com>< 联系我们 - 精彩奇讯科技></a> </span></td>
</tr></table>";
}
?>
--------------------------------------------------------------------------------
本人还是一名在校学生,喜欢Linux并希望以后能从事系统管理方面的工作,希望认识有同样爱好的朋友和以后的同行朋友,我的电子邮箱yukun7402@163.com,QQ740246333
转载于:https://blog.51cto.com/zhaoyukun/400183
Apache-不重启完成添加或更改域名相关推荐
- 虚拟服务器 端口管理,Apache服务配置虚拟主机(基于域名、端口、IP地址)与简单访问权限管理...
虚拟Web主机 在同一台物理服务器中运行多个Web站点,其中每一一个站点并不独立占用一台真正的计算机. httpd支持的虚拟主机类型 基于域名的虚拟主机 基于IP地址的虚拟主机 基于端口的虚拟主机 构 ...
- 初次使用Apache、ip地址、防火墙、域名、DNS、hosts文件、端口、URL介绍、Apache配置文件、配置虚拟主机、请求响应、http协议、
Apache提供web服务: 启动Apache,让其客户端可以使用你机器上安装的Apache提供的web服务,访问你机器上的网站.这种情况下你的计算机就是服务器,别人的机器就是客户端. 注意:确保配置 ...
- (七)活动目录:域控制器更改域名,即修改FQDN名称
域控制器更改域名,即修改FQDN名称 第1步:验证域控制器的FQDN名称 第2步:域控制器添加新FQDN名称 第3步:将新FQDN名称设置为在线模式 第4步:重启域控制器 第5步:删除原FQDN名称 ...
- Apache虚拟主机的配置(基于域名、端口、IP)
一.虚拟主机概述 虚拟 Web 主机指的是在同一台服务器中运行多个 Web 站点,其中的每一个站点实际上并不独立占用整个服务器,因此被称为"虚拟"Web 主机.通过虚拟 Web 主 ...
- windows 2003 活动目录的更改域名后缀技巧
又是作为企业的管理员有许多问题需要解决,通常有这种情况:一个企业的域名后缀由于变更公司名称,导致内部的与环境的域名后缀域公司的名称不相符合,需要 更改,麻烦就来了,更改域名后缀有一定的危险性,万一失败 ...
- 无法更改域名 php网页,WordPress更改新域名后网站无法正常运行怎么办?
很多站长在吐槽WordPress站点更改域名后网站无法正常运行,其实这是一个比较简单的问题,一般新手站长会经常遇到这个问题,那么WordPress更改新域名后网站无法正常运行怎么办? 方法一: 修改w ...
- Docker添加或者更改容器的端口映射
QUESTION:Docker添加或者更改容器的端口映射? ANSWER: 初学Docker容器,按照教程的基本命令,拉取创建了几个容器,都是在一开始新建的时候 docker run -p 指定对应 ...
- 活动目录实战系列五(更改域名)
在单域环境下且没有什么服务的情况的改域名还行,如果网络环境比较复杂或者有其他服务,不建议更改.以免发生错误.在实验中由于虚拟机坏掉在这里使用了两个,有部分图片对不上,请谅解. WIN2000域不支持域 ...
- wordpress忘记登录密码,更改域名的办法。
我们配置wordpress的时候常犯这样的错误:改了域名才发现域名还没解析过来,用自动生成的密码却忘了保存. 这时候,我们需要更改域名或修改wordpress登录密码. 修改登录密码 登上数据库,如果 ...
最新文章
- 聊聊用户裂变的那些事
- 单片机中存储器扩展位地址线怎么算_关于单片机外扩存储器的编址方法
- Openstack Nova 源码分析 — RPC 远程调用过程
- 基于注解的方式配置bean
- lora信号测试小助手_LoRa是如何通过CAD来实现唤醒的
- python showinfo 方法_Python GUI之tkinter窗口视窗教程大集合(看这篇就够了)
- 继续推荐几款VisualStudio的插件
- mysql中游标能不能更新数据库_MySQL与MariaDB中游标的使用
- 常用数据类型使用转换详解
- 示例1---从记事本中读取数值,然后写到数组中---切片,优化版本
- java实验指导书 eclipse_《Java语言程序设计实验指导书》实验指导书.doc
- 从狄仁杰的测字占卜到一淘网的Query分析
- 联想g400从u盘启动计算机,【联想G40怎么从U盘启动】联想g40怎么设置u启动_联想g40从u盘启动...
- 洛杉矶儿童医院被列为美国西部第一,在全美儿童医院中的总体排名升至第五
- 爬取美女图片实现翻页
- 《让子弹飞》系列——张麻子的斗争策略
- 解锁的Facebook其实是很容易的
- SSM学习笔记4(Spring整合Mybatis,P26-P28,真吉尔难)
- web开发指南_成为专业Web开发人员的实用指南
- linux:通过rpm包部署FTP服务