<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>a2query &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/a2query/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Wed, 04 Dec 2019 00:58:33 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>a2query &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Ubuntu 16.04 設定 Apache VirtualHost</title>
		<link>https://noter.tw/3980/ubuntu-16-04-%e8%a8%ad%e5%ae%9a-apache-virtualhost-2/</link>
					<comments>https://noter.tw/3980/ubuntu-16-04-%e8%a8%ad%e5%ae%9a-apache-virtualhost-2/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sat, 23 Jun 2018 03:56:17 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[virtualhost]]></category>
		<category><![CDATA[a2ensite]]></category>
		<category><![CDATA[a2query]]></category>
		<category><![CDATA[a2dissite]]></category>
		<guid isPermaLink="false">https://wazai.net/?p=3980</guid>

					<description><![CDATA[<p>一直以來小蛙一拿到 VPS 就直接把肥胖的 apache 刪除了，早期多半使用 lighttpd，後來比較有時間後全面改成 nginx，這篇留給自己做紀錄，怎麼設定 Apache 的 VirtualH&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3980/ubuntu-16-04-%e8%a8%ad%e5%ae%9a-apache-virtualhost-2/" data-wpel-link="internal">Ubuntu 16.04 設定 Apache VirtualHost</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>一直以來小蛙一拿到 VPS 就直接把肥胖的 apache 刪除了，早期多半使用 lighttpd，後來比較有時間後全面改成 nginx，這篇留給自己做紀錄，怎麼設定 Apache 的 VirtualHost。 </p>



<span id="more-3980"></span>



<p>朋友說他有另一個 domain 要對應到主機上，但是 dns 已經指過去了，連進去卻遇到一堆奇怪的事，例如：路徑明明指向 /var/www/html/aaaa，瀏覽器連進去卻出現指向 /var/www/html/ 的 index &#8230;，或是明明檔案就放在對的路徑，連進去卻是 404 Not Found 或是 403 Forbidden，朋友只好向小蛙求助。

</p>



<p>But &#8230; 小蛙也不太會設定 apache 啊！大概測試了一下，不知道怎麼處理直接丟 Google，看了官方的 VirtualHost 設定的文件，立馬發現 &#8230; 自己根本完全寫錯，這樣 apache 還可以執行，真是太強大了，瞎貓碰到死耗子。 </p>



<p>接下來小蛙記錄自己的做法，由於不確定有沒有更好的辦法，如果你剛好也不知道怎麼辦，不妨試試。 </p>



<h2 class="para wp-block-heading">建立 VirtualHost </h2>



<p>前往 host 設定路徑(可能不同版本或不同安裝方法會有不同路徑)</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">cd /etc/apache2/site-available/</pre>



<p>這裡應該會有一個預設的 000-default.conf 及 default-ssl.conf，前者是 http 設定，後者是 https 基本設定，小蛙寫不出這些設定檔，最快的方式是直接複製一份出來改裡面的設定。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">cp 000-default.conf 001-mydomain.conf  // 換成自己可以辨識的名字就好了
cp default-ssl.conf mydomain-ssl.conf
vim 001-mydomain.conf</pre>



<p>基本內容大概會長這樣</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">&lt;VirtualHost *:80&gt;
    # 自己要對應的 domain
    ServerName mydomain.com  
    ServerAdmin webmaster@localhost
    # 自己的 web 路徑
    DocumentRoot /var/www/html/mydomain/ 
    # 這可以設定 log 等級
    #LogLevel info ssl:warn
    # log 檔案路徑
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
&lt;/VirtualHost&gt;</pre>



<p>編輯完後存檔，這邊就不討論 ssl 的設定了。apache 的設計邏輯是 site-available 放置可以使用的網站設定，但是實際上會載入的網站則是在 site-enabled，所以剛剛設定的站台，目前並不會生效，必須再透過指令啟動。這個動作小蛙的理解是 apache 會把 site-available 裡，指定的設定檔建一份軟連結到 site-enabled 裡面，而 apache 就去啟動 site-enabled 裡面的。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">a2ensite 001-mydomain.conf
Enabling site 001-mydomain.
To activate the new configuration, you need to run:
  service apache2 reload</pre>



<p>這邊小蛙還額外做一件事，就是把 default 的設定拿掉，做這些動作後都別忘了重啟 apache 喔！</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">a2dissite 000-default.conf
Site 000-default disabled.
To activate the new configuration, you need to run:
  service apache2 reload</pre>



<p>要查看目前有哪些站點是生效的除了進入上述的 site-enabled 目錄查看外，也可以直接透過以下指令</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">a2query -s
domain2-ssl (enabled by site administrator)
mydomain-ssl (enabled by site administrator)
002-domain2 (enabled by site administrator)
001-mydomain (enabled by site administrator)</pre>



<p>大概就記錄到這邊了，希望能幫助到有需要的人。 </p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3980/ubuntu-16-04-%e8%a8%ad%e5%ae%9a-apache-virtualhost-2/" data-wpel-link="internal">Ubuntu 16.04 設定 Apache VirtualHost</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/3980/ubuntu-16-04-%e8%a8%ad%e5%ae%9a-apache-virtualhost-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
