24h購物| | PChome| 登入
2020-04-02 03:32:06| 人氣18| 回應0 | 上一篇
推薦 0 收藏 0 轉貼0 訂閱站台

ApacheVirtualHost多網域網站放置在同一台主機

4K輸出 三維智能 品牌行銷 SEO系統維護 影像輸出 AI三維科技

 在 Apache 上設定 VirtualHost 是牙齒掉下來然後又腐化掉的問題,但這問題又久久才會處理一次,剛不小心出了一點小問題,於是稍微記錄一下提醒自己。

設定 VirtualHost 目的是使用同一個伺服器架設多個網站,當使用者以不同網域名稱連到該主機時, web server 會依據不同的目的網頁需求,回應不同的網頁內容。

-----------------------------------------------------------------------------------------

基本的說完,底下來看怎麼設定 Virtual Host

Step 0:DNS 主機設定多個網域名稱對應到同一台主機
Step 1:修改 /etc/httpd/conf/httpd.conf
Step 2:重新啟動 httpd 測試
Step 3:更好的作法
--------------------------------

Step 1:修改 /etc/httpd/conf/httpd.conf
sudo vi /etc/httpd/conf/httpd.conf

當你單一網站的 apache 設定好後,你的 /etc/httpd/conf/httpd.conf 便可以正確的指定到你第一個網頁的 DocumentRoot ,而在 httpd.conf 的最底下會有 Virtual Host 設定的相關提示

意即要開啟 Virtual Host 功能只要將範例的參數(底下標示粗體斜體字)改成你的環境參數就OK了

底下例子以上面綠底圖範例作說明 www.n.com 為第一個網站a.n.com 為第二個增加的網站

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@a.n.com
    DocumentRoot /www/docs/n/a
    ServerName a.n.com
    ErrorLog logs/a.n.com-error_log
    CustomLog logs/a.n.com-access_log common
</VirtualHost>

QQ:那我犯的錯誤在哪?
Ans:原本的 httpd.conf 設定只要綁定 IP:port 跟預設的 DocumentRoot 就能呈現你第一個原始的網站,即使你 ServerName 不改都能正常的運作。
但是~~啟用 virtualhost 後,他是以使用者要求的網域名稱來判斷該回應哪個網頁內容回去
所以~~你必須也寫一段原本網頁的 VirtualHost 片段
如果~~漏了這步驟,只有指定 virtual host 的網站才能呈現,原本的網站網址會出現 Internal Server Error
於是~~要多寫一段關於原本網頁的 virtual host

<VirtualHost *:80>
    ServerAdmin webmaster@www.n.com
    DocumentRoot /www/docs/n
    ServerName www.n.com
    ErrorLog logs/www.n.com-error_log
    CustomLog logs/www.n.com-access_log common
</VirtualHost>

再加入第三個網站,只需要再增加 xx.n.com 的 virtualhost 片段即可

<VirtualHost *:80>
    ServerAdmin webmaster@xx.n.com
    DocumentRoot /www/docs/n/xx
    ServerName xx.n.com
    ErrorLog logs/xx.n.com-error_log
    CustomLog logs/xx.n.com-access_log common
</VirtualHost>

Step 2:重新啟動 httpd 測試
sudo service httpd restart

 

Step 3:更好的作法

在 /etc/httpd/conf/httpd.conf 裡增加專屬於 virtualhost 的設定檔,並且 include 近來

sudo vi /etc/httpd/conf/httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

sudo vi /etc/httpd/conf/extra/httpd-vhosts.conf  預設可能沒有這個檔案,要自行增加

然後把上面字體「藍色字」的設定部分,全部移動到這個檔案中,然後重新啟動就搞定了~~
sudo service httpd restart

 

~End

< type="text/javascript" src="https://ssp.hinet.net/api/app.js">
< language="javascript">(function(){$('#content_all img').map((function(){var skip_count = 2;return function(){var $this = $(this);if(this.src.indexOf('.gif') == -1) {var data = {title: this.title || this.alt || '',description: '',src: this.src,size: 'o',href: $this.parent('a')};if(data.href.length != 0) {data.href = data.href[0].href;} else {data.href = '#';}if(skip_count <= 0) {var src = this.src;$(this).addClass('lazyload').attr({'src': 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7','data-original': src});} else {skip_count--;}}return this;};})());$(function(){$('#content_all img.lazyload').lazyload({threshold: 600,load: function() {$(this).removeClass('lazyload');if( BlogPlugins && BlogPlugins.auto_resize &&(typeof xuiteBlogPlugin_auto_resize=="undefined") || (xuiteBlogPlugin_auto_resize == null) || (xuiteBlogPlugin_auto_resize == 'Y') ) {BlogPlugins.auto_resize(this, null, {delay:1000});}}});});})();var itemArticleDetailType = "";if(getCookie("xuite_id") != null && itemArticleDetailType != "article_preview"){$.ajax({type: "GET",url: "/_theme/AuthorButtonExp.php?aid=485166953&bid=728051&mid=16997768&author_id=16997768&article_type=blog&ga="+(new Date()).getTime(),async: false,dataType: 'json',success: getButton});}function getButton(json){document.write("
"+json+"
");}if ((typeof xuiteBlogPlugin_auto_yo=="undefined") || (xuiteBlogPlugin_auto_yo == null) || (xuiteBlogPlugin_auto_yo == 'Y')) {$.ajax({type: "GET",url: "//s.blog.xuite.net/_public/js/BlogPlugins.auto_yo.js",success: function(){BlogPlugins.auto_yo.fetchItem(485166953);},dataType: "script",cache: true});}
< language="javascript">if ((typeof xuiteBlogPlugin_facebook_comment=="undefined") || (xuiteBlogPlugin_facebook_comment == null) || (xuiteBlogPlugin_facebook_comment == 'Y')){var myBlogThemeWidth = $(".title").width()-38;if ((typeof xuiteBlogPlugin_facebook_comment_color=="undefined") || (xuiteBlogPlugin_facebook_comment_color == null) || (xuiteBlogPlugin_facebook_comment_color == 'Y')){document.write('
'+'
');}else {document.write('
'+'
');}(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = "//connect.facebook.net/zh_TW/sdk.js#xfbml=1&version=v2.0";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));}if ((typeof xuiteBlogPlugin_facebook_like_down == "undefined") || (xuiteBlogPlugin_facebook_like_down == null) || (xuiteBlogPlugin_facebook_like_down == 'Y')){$(document).ready(function(){(new XUI.Widgets.Like(document.getElementById('facebook-like-bottom'), { mode : 'face' , URL : 'http://blog.xuite.net/tolarku/blog/485166953' })).render();});}
< language="javascript">var notVIP = '
';$(".articleExtAd").append(notVIP);setTimeout(function() {$('.top-toolbar').data('top-toolbar').setAD({title: "Apache Virtual Host \u591a\u7db2\u57df\u7db2\u7ad9\u653e\u7f6e\u5728\u540c\u4e00\u53f0\u4e3b\u6a5f\u4e0a",label_id: 166,label_name: "\u7a0b\u5f0f\u8a2d\u8a08"});}, 2000);
< language="javascript">if( (typeof xuiteBlogPlugin_random_article=="undefined") || (xuiteBlogPlugin_random_article == null) || (xuiteBlogPlugin_random_article == 'Y') || (xuiteBlogPlugin_random_article == 'YY') ){$(".articleExt").append('
');var random_content = '
    ';$(".articleExt").append(random_content);$.get("/_theme/ArticleRandomExp.php?bid=728051&plugin_random="+xuiteBlogPlugin_random_article+"&theme_type=&tpl_type=1", function(data){$("#articleExt_random_content").append(data);if(data != null && data != ""){$("#articleExt_random_title").append("隨機文章 : ");if(xuiteBlogPlugin_random_article == "YY"){$("ul#articleExt_random_content").attr("class","");}}});}if( (typeof xuiteBlogPlugin_relate_article=="undefined") || (xuiteBlogPlugin_relate_article == null) || (xuiteBlogPlugin_relate_article == 'Y')){$(".articleExt").append('
    ');}else{$(".articleExt").append('
    ');}if( (typeof xuiteBlogPlugin_history_today=="undefined") || (xuiteBlogPlugin_history_today == null) || (xuiteBlogPlugin_history_today == 'Y')){$(".articleExt").append("
    歷史上的今天:
    ");}(function() {var pa = document.createElement('script'); pa.type = 'text/javascript'; pa.charset = "utf-8"; pa.async = true;pa.src = window.location.protocol + "//api.popin.cc/searchbox/xuite_blog.js";var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(pa, s);})();
    AR全息投影 SEO網站優化 三維智能 大心國際 動畫設計 AR廣
    回應
    < language="javascript"> function wopen(){ window.open("//blog.xuite.net/_theme/item/item_auto_trackback.php?ping=https://blog.xuite.net/tolarku/blog/485166953/track","trackBack","location=no,toolbar=no,resizable=yes,scrollbars=yes,width=430,height=400") } function copy_clip(meintext) { if (window.clipboardData) { // the IE-manier window.clipboardData.setData("Text", meintext); } } function openSpecfiyWindown(windowName){ window.open('about:blank',windowName,'width=800,height=600,menubar=no,scrollbars=yes'); } function doMsgDelete(mid,page){ if(confirm("是否確定要刪除")){ $("div.jqmWindow").html(""); } } function doTrackDelete(tid,lid,url,page){ if(confirm("是否確定要刪除")){ $("div.jqmWindow").html(""); } } function doMsgEdit(mid,page){ var l="/_theme/message/message_post.php?act=edit&mid="+mid+"&aid=485166953&bid=728051&page="+page; window.open(l,'post_win','width=660,height=700,scrollbars=1'); } function doMsgReplyAdd(rel_id,page,owner_sn,owner_login_id){ var l="/_theme/message/message_post.php?act=reply&rel_id="+rel_id+"&aid=485166953&bid=728051&page="+page+"&owner_sn="+owner_sn+"&owner_login_id="+owner_login_id; window.open(l,'post_win','width=660,height=700,scrollbars=1'); } function doMsgReplyEdit(mid,page){ var l="/_theme/message/message_post.php?act=reply_edit&mid="+mid+"&aid=485166953&bid=728051&page="+page; window.open(l,'post_win','width=660,height=700,scrollbars=1'); } function doSummary(arg){ $("#summarySwitch").html($("#summaryContent").html()); $("#summaryContent").html($("#summaryDisplay").html()); $("#summaryDisplay").html($("#summarySwitch").html()); } < language="javascript"> $(document).ready(function(){ var index=""; Message(485166953,728051,16997768,16997768,index); TrackBack('485166953','tolarku','blog','16997768','728051','16997768','Y',index); if ((typeof xuiteBlogPlugin_auto_resize=="undefined") || (xuiteBlogPlugin_auto_resize == null) || (xuiteBlogPlugin_auto_resize == 'Y')) { $.ajax({ type: "GET", url: "//s.blog.xuite.net/_public/js/BlogPlugins.auto_resize.js", success: function(){ BlogPlugins.auto_resize("#content_all img", null, {delay:1000}); }, dataType: "script", cache: true }); } $.ajax({ type: "GET", url: '/_theme/ArticleDetailCounterExp.php?aid=485166953&ga='+(new Date()).getTime(), dataType: 'json', success: getArticleDetailCounter }); }); function getArticleDetailCounter(json){ $("#article_counter").html(json[0].counter); } function TrackBack(aid,b_login,b_url,mid,bid,a_author_id,track_flag,index){ $.ajax({ type: "GET", url: '/_theme/TrackBackShowExp.php?aid='+aid+'&b_login='+b_login+'&b_url='+b_url+'&mid='+mid+'&bid='+bid+'&a_author_id='+a_author_id+'&track_flag='+track_flag+'&index='+index+'&ga='+(new Date()).getTime(), dataType: 'json', async: false, success: getTrackBackShow }); } function Message(aid,bid,uid,a_author_id,index){ $("div.item_message").html(""); $("div.alertLoad").ajaxStart(function(){ $(this).show(); }); $("div.alertLoad").ajaxStop(function(){ $(this).hide(); $(this).unbind("ajaxStart"); }); var mid = ""; if (index == "" && location.hash != '#message_header') { mid = location.hash.replace("#",""); } $.ajax({ type: "GET", url: '/_theme/MessageShowExp.php?ver=new&aid='+aid+'&uid='+uid+'&bid='+bid+'&a_author_id='+a_author_id+'&index='+index+'&mid='+mid+'&ga='+(new Date()).getTime(), dataType: 'json', async: false, success: getMessageShow }); } function getMessageShow(json){ $("div.item_message").html(json['message'].content); $("div.alertLoad").hide(); if(json['aside'].check != 0){ for( i =0; i < json['aside'].length; i++){ $("div#authorname_"+json['aside'][i].id).html("
    (這則留言是悄悄話)
    "); $("div#commenttext_"+json['aside'][i].id).html(json['aside'][i].content); } } if (json['button'].check != 0){ for( i =0; i < json['button'].length; i++) { if(json['button'][i].level == 'all'){ /*是回覆*/ if(json['button'][i].relation_id != null && json['button'][i].relation_id != undefined){ $("div#commentbutton_"+json['button'][i].relation_id).html(" 修改回覆   回覆刪除"); /*是回應*/ }else{ /*有回覆*/ if($("div#reply_"+json['button'][i].id).html() != null){ $("div#commentbutton_"+json['button'][i].id).html(" 修改   刪除"); /*沒回覆*/ }else{ if(json['button'][i].self_write != 'y'){ $("div#commentbutton_"+json['button'][i].id).html(" 修改   刪除"); }else{ $("div#commentbutton_"+json['button'][i].id).html(" 新增回覆    修改   刪除"); } } } }else if(json['button'][i].level == 'one'){ /*是回覆*/ if(json['button'][i].relation_id != null && json['button'][i].relation_id != "undefined"){ $("div#commentbutton_"+json['button'][i].relation_id).html(" 修改回覆   回覆刪除"); /*是回應*/ }else{ /*有回覆*/ if($("div#reply_"+json['button'][i].id).html() != null){ $("div#commentbutton_"+json['button'][i].id).html("刪除"); /*沒回覆*/ }else{ if(json['button'][i].self_write != 'y'){ $("div#commentbutton_"+json['button'][i].id).html("刪除"); }else{ $("div#commentbutton_"+json['button'][i].id).html(" 新增回覆   刪除"); } } } //放上ip }else{ $("div#commentbutton_"+json['button'][i].id).html(" 修改   刪除"); } } } if (json['reload'].flage != "true"){ ff= location.href; tt = ff.indexOf("#"); if(tt != -1){ o_index =ff.substring(0,tt); location.href="https://blog.xuite.net/tolarku/blog/o_index+"#message_header"; }else{ location.href="https://blog.xuite.net/tolarku/blog/ff+"#message_header"; } } } function getTrackBackShow(json){ $("div.item_trackBack").html(json['trackBack'].content); if(json['button'].check != 1){ $("div.track_button").hide(); } if(json['reload'].flage != "true"){ ff= location.href; tt = ff.indexOf("#"); if(tt != -1){ o_index =ff.substring(0,tt); location.href="https://blog.xuite.net/tolarku/blog/o_index+"#trackBack_header"; }else{ location.href="https://blog.xuite.net/tolarku/blog/ff+"#trackBack_header"; } } } var pinnedSite = new XUI.Widgets.PinnedSite( { title: "Apache Virtual Host 多網域網站放置在同一台主機上", author: "tolarku", url: "http://blog.xuite.net/tolarku/blog/485166953" } ); pinnedSite.render();
    < language="javascript">var searchClickFlag='false';function Trim(TRIM_VALUE){if(TRIM_VALUE.length < 1){return"";}TRIM_VALUE = RTrim(TRIM_VALUE);TRIM_VALUE = LTrim(TRIM_VALUE);if(TRIM_VALUE==""){return "";}else{return TRIM_VALUE;}}function RTrim(VALUE){var w_space = String.fromCharCode(32);var v_length = VALUE.length;var strTemp = "";if(v_length < 0){return"";}var iTemp = v_length -1;while(iTemp > -1){if(VALUE.charAt(iTemp) == w_space){}else{strTemp = VALUE.substring(0,iTemp +1);break;}iTemp = iTemp-1;}return strTemp;}function LTrim(VALUE){var w_space = String.fromCharCode(32);if(v_length < 1){return"";}var v_length = VALUE.length;var strTemp = "";var iTemp = 0;while(iTemp < v_length){if(VALUE.charAt(iTemp) == w_space){}else{strTemp = VALUE.substring(iTemp,v_length);break;}iTemp = iTemp + 1;}return strTemp;}function blog_search_chk(){if(Trim(document.search_form.w.value)==""){alert('請輸入要查詢關鍵字!!');document.search_form.w.focus();return false;}else if(document.search_form.w.value.indexOf('*')!=-1){alert('請輸入要查詢關鍵字!');document.search_form.w.focus();return false;}else if(document.search_form.w.value==""){alert('請輸入要查詢關鍵字!');document.search_form.w.focus();return false;}else{return true;}}
    < language="javascript" type="text/javascript">document.write(g_sidebar.ItemSearch);
    關鍵字
    Google Search
    Google
    < language="javascript" type="text/javascript"> $(document).ready(function(){ $.ajax({ type: "GET", url: '/_theme/CountSideExp.php?bid=728051&ga='+(new Date()).getTime(), dataType: 'json', success: getCountSide }); }); function getCountSide(json){ $("div#todayHit").html("今日人氣: "+json.now_hit); $("div#totalHit").html("累積人氣: "+json.all_hit); }
    < language="javascript" type="text/javascript">document.write(g_sidebar.ItemCounter);
    < language="javascript" type="text/javascript">document.write(g_sidebar.ItemCategory);
    < language="javascript" type="text/javascript">document.write(g_sidebar.ItemArticleHotList);
    累積 | 今日
    loading......
    < type="text/javascript">var loginID = 'tolarku';var blogUrl = 'blog';var bid = '728051';$(document).ready(function() {getHot('history');});function getHot(hotType){$.ajax({type: "GET",url: "/_theme/HotArticleExp.php",data: "type="+hotType+"&bid="+bid,dataType: "json",success: function(json){$(".hotArticleSide").html('');for (var i = 0; i < json.length; i++) {var strLocation = location.href;if (strLocation.match("blog.xuite.net") != null) {$(".hotArticleSide").append('
  • ' + json[i].title + '
  • ');}else {$(".hotArticleSide").append('
  • ' + json[i].title + '
  • ');}}if( json.length == 0)$(".hotArticleSide").append('今天生意不好喲~~');else {$("#ah_loading").hide();}}});} < language="javascript">$(document).ready(function(){Score_Set(0);setblogRank(30,4)});function Score_Set(idx){if(idx < 0 || idx > 5)return;var i, line;line='';for(i=1;i <=idx;i++){line+='';}for(i=idx+1;i <=5;i++){line+='';}document.getElementById('SelectScore').innerHTML=line;if(idx > 0){window.status='給 '+idx+' ';}else{window.status='';}}function Score_Send(score){if( document.cookie.indexOf("Nickname") == -1){if(confirm("請先登入Xuite會員")){document.location.href="https://blog.xuite.net/_members/login.php?furl="+location.href;return;}else{return;}}if(!confirm('您已將這個日誌評分為 '+score+' 。按一下 [確定] 表示確認。')){return;}document.location.href="https://blog.xuite.net/_theme/doRank.php?type=blog&relate_id=728051&stars="+score;}function setblogRank(inMen,inStars){var Stars = document.all ? document.all('rank_average_stars') : document.getElementById('rank_average_stars');Stars.innerHTML = inStars;var Men = document.all ? document.all('rank_men') : document.getElementById('rank_men');Men.innerHTML = inMen;}
    < language="javascript" type="text/javascript">document.write(g_sidebar.ItemRank);
    平均分數:0 顆星
    投票人數:0
    我要評分:
    Google
    < src="https://my.xuite.net/api/visit.php?key=aHR0cDovL2Jsb2cueHVpdGUubmV0L3RvbGFya3UvYmxvZw==" type="text/javascript"> < type="text/javascript" src="https://static.adsinstant.com/xuite/fgm.js">


    文章來自: https://blog.xuite.net/tolarku/blog/485166953-Apache+Virtual+Host+%E5%A4%9A%E7%B6%B2%E5%9F%9F%E7%B6%

    我要檢舉
    台長: katierdy3
    人氣(18) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
    全站分類: 星座命理(星座、命理、心理測驗) | 個人分類: SEO網站優化 |

    是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
    * 請輸入識別碼:
    請輸入圖片中算式的結果(可能為0) 
    (有*為必填)
    TOP
    詳全文