Apache-不重启完成添加或更改域名
?? ? 這兩天開始學(xué)習(xí)Linux環(huán)境下配置Apache服務(wù)器,結(jié)合現(xiàn)在行業(yè)實(shí)況,我特地注意學(xué)習(xí)了虛擬主機(jī)的配置方法,我買的書上講的方法是在httpd.conf文件中添加VirtualHost來實(shí)現(xiàn)的,經(jīng)過實(shí)踐也成功了,但是這個方法需要在配置后重啟httpd服務(wù)才能生效,下面我就介紹一種無需重啟Apache即可更改域名、網(wǎng)站根目錄的方法。
注:本方法來源于網(wǎng)上,本人還沒有青紫實(shí)踐。
第一步
打開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文件里添加相應(yīng)記錄,并建立相應(yīng)文件夾就OK了~~~?
其實(shí)這個可以用php腳本來完成的,很簡單的~~呵呵~~~,就像現(xiàn)在的虛擬主機(jī)提供商一樣,允許用戶自行綁定域名。
注意啊:php_admin_value open_basedir “path",這個選項要配好啊~~新手如果不懂的,就不要動這個了
======================================================
貼一個簡單的vhost.map文件的操作代碼。。。隨意寫的,根據(jù)你自己的實(shí)際情況稍加修改就可以實(shí)現(xiàn)在線管理域名綁定了。
<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>精彩奇訊科技虛擬主機(jī)自助申請系統(tǒng)</a> 請?zhí)顚懽孕畔?lt;/th>?
?? ? ? ?</tr>?
?? ? ? ?<tr>?
?? ? ? ? ? ? ? ?<td class="row2" colspan="2"><span class="gensmall">請輸入在本服務(wù)器新增的域名:</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="發(fā)送" class="mainoption" /> <input type="reset" value="重設(shè)" 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];?
?? ?// 檢查并創(chuàng)建目錄開始*******************************?
?? ?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\">此域名已經(jīng)使用,請更換~~<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>點(diǎn)擊查看已開空間</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\">空間開設(shè)成空!~~<a href=$PHP_SELF>返回</a></span><span class=\"gensmall\"> ?<a href=$domain target=_blank><FONT COLOR=BLUE>點(diǎn)擊查看已開空間</FONT></a> <a href=http://www.sun126.com>< 聯(lián)系我們 - 精彩奇訊科技></a> </span></td>?
?? ? ? ?</tr></table>";?
}?
?>
--------------------------------------------------------------------------------
本人還是一名在校學(xué)生,喜歡Linux并希望以后能從事系統(tǒng)管理方面的工作,希望認(rèn)識有同樣愛好的朋友和以后的同行朋友,我的電子郵箱yukun7402@163.com,QQ740246333
轉(zhuǎn)載于:https://blog.51cto.com/zhaoyukun/400183
總結(jié)
以上是生活随笔為你收集整理的Apache-不重启完成添加或更改域名的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ASP.NET : Kerberos网络
- 下一篇: VMware Workstation(虚