<?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>Web Server &#8211; 記下來</title>
	<atom:link href="https://noter.tw/server/web-server/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Tue, 21 May 2024 02:10:18 +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>Web Server &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)</title>
		<link>https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/</link>
					<comments>https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Fri, 07 Oct 2022 12:43:49 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu Apache SSL]]></category>
		<category><![CDATA[TWCA CSR]]></category>
		<category><![CDATA[TWCA CER]]></category>
		<category><![CDATA[產生 TWCA CSR]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[Private Key]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[如何生成 CSR]]></category>
		<category><![CDATA[TWCA]]></category>
		<category><![CDATA[如何生成 private key]]></category>
		<category><![CDATA[SSL 憑證申請]]></category>
		<category><![CDATA[CSR]]></category>
		<category><![CDATA[TWCA 憑證申請教學]]></category>
		<category><![CDATA[TWCA 憑證]]></category>
		<category><![CDATA[TWCA SSL Apache]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=10420</guid>

					<description><![CDATA[<p>因為某些特殊緣故必須要向 TWCA (臺灣網路認證) 申請 SSL 憑證，已經申請好幾次了，每次做都還要去查資料，這篇文章把向 TWCA 申請 SSL 憑證的流程記下來。</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/" data-wpel-link="internal">向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>因為某些特殊緣故必須要向 <a href="https://www.twca.com.tw/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">TWCA<span class="wpel-icon wpel-image wpel-icon-6"></span></a> (臺灣網路認證) 申請 SSL 憑證，已經申請好幾次了，每次做都還要去查資料，這篇文章把向 TWCA 申請 SSL 憑證的流程記下來。</p>



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



<p><a href="https://www.twca.com.tw/service_detail/7d08f851-9415-4dd7-92cc-91ee37fb7b69" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">TWCA 官網<span class="wpel-icon wpel-image wpel-icon-6"></span></a>列出申請 SSL 憑證總共有 6 個步驟，接下來小蛙會著重在第 3 步：<strong>上傳 CSR (WEB)</strong> 以及第 6 步：<strong>安裝與設定 1.電子憑證 2.認證標章</strong> (但不會使用認證標章)</p>



<h2 class="wp-block-heading para">申請 TWCA SSL 憑證：上傳 CSR (WEB)</h2>



<h3 class="wp-block-heading para">產生主機 KEY 及 CSR 憑證請求檔</h3>



<p>首先進到 /etc/ssl/ 產生金鑰 (private key)</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cd /etc/ssl/
openssl genrsa -out server.key 2048</pre>



<p>使用這把金鑰產生 CSR 憑證請求檔</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">openssl req -new -key ./server.key -out server.csr

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]: TW (國家縮寫)
State or Province Name (full name) [Some-State]:Taiwan (國家名稱全名)
Locality Name (eg, city) []:Taichung (城市名稱)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Noter (公司名稱) 
Organizational Unit Name (eg, section) []:IT (部門名稱)
Common Name (e.g. server FQDN or YOUR name) []:noter.tw (網域名稱)
Email Address []:noter.tw@gmail.com (電子郵件)

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:Noter (選用的公司名稱)</pre>



<p>2024-05-21 補充，因為每年都要產生一次，有時候忘記 CSR 要輸入的東西，就可以使用以下指令來看查看之前產生 CSR 時填入的資訊</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">openssl req -in example.csr -noout -text</pre>



<h3 class="wp-block-heading para">上傳 CSR</h3>



<p>經過上述步驟後，在 <code>/etc/ssl/</code> 下會多出 <code>server.key</code> 及 <code>server.csr</code>，回到 <a href="https://www.twca.com.tw/service_detail/7d08f851-9415-4dd7-92cc-91ee37fb7b69" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">TWCA 官網<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 第 3 點的描述</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>請將CSR檔案中的內容複製到下方的空欄中，注意複製的範圍應包括「&#8212;&#8211;BEGIN NEW CERTIFICATE REQUEST&#8212;&#8211;」到「&#8212;&#8211;END NEW CERTIFICATE REQUEST&#8212;&#8211;」的宣告文字。</p>
</blockquote>



<p>透過 cat 印出剛剛產生的 CSR</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cat server.csr

-----BEGIN CERTIFICATE REQUEST-----
...
...
...
-----END CERTIFICATE REQUEST-----</pre>



<p>複製「&#8212;&#8211;BEGIN NEW CERTIFICATE REQUEST&#8212;&#8211;」到「&#8212;&#8211;END NEW CERTIFICATE REQUEST&#8212;&#8211;」範圍的文字，貼到 TWCA 官網中點擊繼續</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEUii6S1K0_-GAxZTQ4PT-RTlxjCuLFkpe0VAvFwfpE3q-pmUMS82NLzMZ2EFsIqYzIdmvBthfhNlrBwzdp4ZaPJ_-EO8dD-UrJXL9i3N8OVr6_0InU84JukzuF3U7-NRe6klxRdVJmd6_Im7_qySb_5=w1045-h542-no?authuser=1" alt="TWCA SSL 憑證：上傳 CSR 1" style="width:784px;height:407px" title="向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)"></figure></div>


<p>確認紅框內的資訊後，輸入密碼、選擇驗證網域的方式、及表單編號</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEUqolhtYlj23TU_asHRoGOkYyLZmY0q1f9IvsjnYS55DsJ6EXJ_g8Id2rfakMgph2jwTvRMeYCobOnt9aFObIzIpfaXtEzkp4FkCwmmLJGGqe2-1o80Rk97cSPzuNNHBsDYtGfHbNsTAObyCkZbefFI=w1108-h1023-no?authuser=1" alt="TWCA SSL 憑證：上傳 CSR 2" title="向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)"></figure></div>


<p>點擊繼續後即上傳完成</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEXQAtelMnZH8S-ITRuLhOr_yzNo6nLJJxRRNiIJO5kY_QpojlFzhT28LG7o6d86OqZO_3UsYZhqy6zzmF-VaMOpcD8rSz11S1rDIGYbdjthRH0dahHm_3d5MOAOdGERglUcxgj85jDs9raoXsL5OK2p=w684-h245-no?authuser=1" alt="TWCA SSL 憑證：上傳 CSR 3" style="width:513px;height:184px" title="向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)"></figure></div>


<h3 class="wp-block-heading para">驗證網域所有權</h3>



<p>小蛙這邊使用的是「網站檔案驗證」(上一步選擇的)，收到操作手冊與驗證檔</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEX4VoKr55HSOfIw9uQM_tnFTnwFi66y-mKKKeoMZ7nGDLhSXbn-W7-zYebDhdnOroC_NaWLwg2WgTPrSsC1szr1c3FyAi8pKZpzme3eZ4uCcSxXKtgjjb28m3z-pcRDHLxPsMiJkWQL8fb62ziSOZEi=w944-h664-no?authuser=1" alt="TWCA SSL 憑證：驗證網域" style="width:708px;height:498px" title="向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)"></figure></div>


<p>在網站根目錄建立對應的資料夾及 <code>whois.txt</code> 檔案，並將 email 附件中的 whois.txt 貼上，也可以直接把附件中的檔案解壓縮後，直接上傳到網站根目錄中。例如小蛙的網站根目錄是 <code>/var/www/html/</code> </p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">mkdir -p /var/www/html/.well-known/pki-validation/
vim /var/www/html/.well-known/pki-validation/whois.txt</pre>



<p>完成後確定從 email 給的連結可以看到剛剛的 whois.txt 檔案，即可與 TWCA 聯繫進行下一步。</p>



<h2 class="wp-block-heading para">安裝與設定 1.電子憑證 2.認證標章</h2>



<p>等待 TWCA 審核完成後收到一封 email 及一個壓縮檔，解壓縮後包含我們前面產生的檔案，共有以下</p>



<ol class="my-li bg-darkblue wp-block-list">
<li>server.key 伺服器金鑰</li>



<li>server.csr TWCA CSR 憑證申請檔</li>



<li>root.cer 根憑證</li>



<li>server.cer 伺服器憑證</li>



<li>uca.cer 中繼憑證</li>
</ol>



<p>這邊會用到的為 1, 4, 5 三個檔案，如果收到的檔案是 <code>uca_1.cer</code> 跟 <code>uca_2.cer</code>，可先透過 <code>cat uca_2.cer uca_1.cer &gt; uca.cer</code> 將檔案合併成一個。</p>



<p>以小蛙自己的環境 Apache2.4 為例，首先複製一份預設的檔案出來改</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default-le-ssl.conf
vim /etc/apache2/sites-available/000-default-le-ssl.conf</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="ini" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;IfModule mod_ssl.c>
&lt;VirtualHost *:443>
        ServerName 改成 TWCA 申請 SSL 的網址
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Include /etc/letsencrypt/options-ssl-apache.conf  # 這個是因為小蛙有使用 letsencrypt
        SSLCertificateFile /etc/ssl/server.cer            # 加上這個
        SSLCertificateKeyFile /etc/ssl/server.key         # 加上這個
        SSLCertificateChainFile /etc/ssl/uca.cer          # 加上這個
&lt;/VirtualHost>
&lt;/IfModule></pre>



<p>儲存後啟用該站點，檢查沒問題後重起 apache 就完成囉！</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">a2ensite 000-default-le-ssl.conf
apache2ctl configtest
Syntax OK
service apache2 graceful</pre>



<p><strong>增加安全性系列：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/10420/向-twca-申請-ssl-憑證-ubuntu-apache/" data-wpel-link="internal">向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)</a></li><li><a href="https://noter.tw/34/ubuntu-16-04-%E5%8D%87%E7%B4%9A-phpmyadmin-%E4%B8%A6%E9%96%8B%E5%95%9F%E4%BA%8C%E9%9A%8E%E6%AE%B5%E9%A9%97%E8%AD%89-2fa/" data-wpel-link="internal">Ubuntu 16.04 升級 phpMyAdmin 並開啟二階段驗證( 2FA )</a></li><li><a href="https://noter.tw/255/ubuntu-16-04-安裝-fail2ban/" data-wpel-link="internal">Ubuntu 16.04 安裝 fail2ban</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/" data-wpel-link="internal">向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Certbot error: ACMEv1 is deprecated and you can &#8230;</title>
		<link>https://noter.tw/9107/certbot-error-acmev1-is-deprecated/</link>
					<comments>https://noter.tw/9107/certbot-error-acmev1-is-deprecated/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Fri, 13 Aug 2021 04:30:00 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[技術相關]]></category>
		<category><![CDATA[apt-get install upgrade]]></category>
		<category><![CDATA[免費 ssl]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[certbot]]></category>
		<category><![CDATA[ACMEv1 is deprecated]]></category>
		<category><![CDATA[upgrad certbot]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=9107</guid>

					<description><![CDATA[<p>今天好友說有一個網站的 SSL 過期了，請小蛙幫忙看一下，下指令更新會出現 Certbot error: ACMEv1 is deprecated 使用免費的 SSL 就要承受每三個月過期一次的麻煩，&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/9107/certbot-error-acmev1-is-deprecated/" data-wpel-link="internal">Certbot error: ACMEv1 is deprecated and you can &#8230;</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>今天好友說有一個網站的 SSL 過期了，請小蛙幫忙看一下，下指令更新會出現 Certbot error: ACMEv1 is deprecated </p>



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



<p>使用<a href="https://noter.tw/3695/ssl-for-free-%e5%85%8d%e8%b2%bb%e5%8f%88%e6%9c%89%e7%b6%a0%e8%89%b2%e9%8e%96%e9%a0%ad%e7%9a%84-ssl-certificates/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">免費的 SSL</a> 就要承受每三個月過期一次的麻煩，但是想想三個月過期一次就可以省一大筆錢，似乎又還蠻划算的～之前遇到很多種奇怪的狀況，這篇記錄一下第一次遇到這種 ACMEv1。</p>



<p>小蛙覺得奇怪，怎麼去年三月到現在已經正常運行那麼久了，卻在這時候突然失靈，輸入 certbot run 的指令後出現 ACMEv1 is deprecated and you can bla bla bla 通常附上的連結點過去都沒什麼結果，直接把相關問題丟 Google 比較實在。</p>



<p>經過一番查詢後才知道原來是 certbot 的版本更新了，原本使用的 ACMEv1 已經不能使用，好友網站是 Ubuntu 16.04 LTS，<a href="https://askubuntu.com/questions/44122/how-to-upgrade-a-single-package-using-apt-get" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">更新<span class="wpel-icon wpel-image wpel-icon-6"></span></a>也很簡單</p>



<pre class="wp-block-preformatted withcode">apt-get install --only-upgrade certbot</pre>



<p>期間可能會連帶更新例如 python3 等相依的套件，等他跑完就完成了！</p>



<p><strong>網站架設系列文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/10151/%e7%9b%a4%e9%bb%9e%e9%82%a3%e4%ba%9b%e6%9b%be%e7%b6%93%e9%99%aa%e4%bc%b4%e9%81%8e%e5%b0%8f%e8%9b%99%e7%9a%84-vps-%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f/" data-wpel-link="internal">盤點那些曾經陪伴過小蛙的 VPS 虛擬主機</a></li><li><a href="https://noter.tw/176/%e5%a6%82%e4%bd%95%e6%8c%91%e9%81%b8-vps-%e6%9c%80%e5%88%92%e7%ae%97%e7%9a%84%e8%b2%b7%e6%b3%95/" data-wpel-link="internal">如何挑選 VPS + 最划算的買法</a></li><li><a href="https://noter.tw/406/%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E5%A6%82%E4%BD%95%E8%B3%BC%E8%B2%B7-vps/" data-wpel-link="internal">手把手教你如何購買 VPS</a></li><li><a href="https://noter.tw/4463/第一次買-kvm-虛擬主機/" data-wpel-link="internal">第一次買 KVM 虛擬主機</a></li><li><a href="https://noter.tw/4242/%e8%a1%80%e7%9a%84%e6%95%99%e8%a8%93-hiformance-%e8%b7%91%e8%b7%af%e4%ba%86/" data-wpel-link="internal">血的教訓 &#8211; HiFormance 跑路了 &#8230;</a></li><li><a href="https://noter.tw/196/%e7%82%ba%e8%87%aa%e5%b7%b1%e7%94%b3%e8%ab%8b%e4%b8%80%e5%80%8b%e5%9f%9f%e5%90%8d-hinet-%e7%82%ba%e4%be%8b/" data-wpel-link="internal">為自己申請一個域名 – HiNet 為例</a></li><li><a href="https://noter.tw/117/cloudflare-%E8%B6%85%E5%BC%B7%E5%A4%A7%E7%9A%84%E5%85%8D%E8%B2%BB-cdn/" data-wpel-link="internal">Cloudflare – 超強大的免費 CDN (?)</a></li><li><a href="https://noter.tw/195/%e4%bd%bf%e7%94%a8-cloudflare-%e4%bb%a3%e7%ae%a1%e4%bd%a0%e7%9a%84%e5%9f%9f%e5%90%8d/" data-wpel-link="internal">使用 Cloudflare 代管你的域名</a></li><li><a href="https://noter.tw/396/ubuntu-16-04-設定環境語言編碼，讓中文可以正常顯示/" data-wpel-link="internal">Ubuntu 16.04 設定環境語言編碼，讓中文可以正常顯示</a></li><li><a href="https://noter.tw/255/ubuntu-16-04-%e5%ae%89%e8%a3%9d-fail2ban/" data-wpel-link="internal">Ubuntu 16.04 安裝 fail2ban</a></li><li><a href="https://noter.tw/436/%E4%B8%80%E5%80%8B%E8%85%B3%E6%9C%AC%E6%AF%8F%E5%A4%A9%E8%87%AA%E5%8B%95%E5%82%99%E4%BB%BD/" data-wpel-link="internal">一個腳本每天自動備份</a></li><li><a href="https://noter.tw/32/linux-tar-%E5%AE%8C%E6%95%B4%E5%82%99%E4%BB%BD%E3%80%81%E5%A2%9E%E9%87%8F%E5%82%99%E4%BB%BD%E5%8F%8A%E5%B7%AE%E7%95%B0%E5%82%99%E4%BB%BD%E6%AF%94%E8%BC%83/" data-wpel-link="internal">Linux tar 完整備份、增量備份及差異備份比較</a></li><li><a href="https://noter.tw/3704/nginx-ssl-certificate-%E8%AE%93-http-%E8%AE%8A%E8%BA%AB%E6%88%90%E7%82%BA-https/" data-wpel-link="internal">nginx + SSL Certificate – 讓 http 變身成為 https</a></li><li><a href="https://noter.tw/3695/ssl-for-free-%E5%85%8D%E8%B2%BB%E5%8F%88%E6%9C%89%E7%B6%A0%E8%89%B2%E9%8E%96%E9%A0%AD%E7%9A%84-ssl-certificates/" data-wpel-link="internal">SSL For Free – 免費又有綠色鎖頭的 SSL Certificates</a></li><li><a href="https://noter.tw/8596/certbot-error/" data-wpel-link="internal">Certbot 申請 SSL certificate 錯誤問題</a></li><li><a href="https://noter.tw/9107/certbot-error-acmev1-is-deprecated/" data-wpel-link="internal">Certbot 錯誤：ACMEv1 is deprecated and you can …</a></li><li><a href="https://noter.tw/5967/ubuntu-18-04-%e5%ae%89%e8%a3%9d-awstats-%e4%be%86%e7%b5%b1%e8%a8%88%e7%b6%b2%e7%ab%99%e6%b5%81%e9%87%8f/" data-wpel-link="internal">Ubuntu 18.04 安裝 AWStats 來統計網站流量</a></li><li><a href="https://noter.tw/9287/pchome-%e8%b2%b7%e7%b6%b2%e5%9d%80%e7%ba%8c%e7%b4%84%e6%b5%81%e7%a8%8b/" data-wpel-link="internal">PCHome 買網址續約流程</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/9107/certbot-error-acmev1-is-deprecated/" data-wpel-link="internal">Certbot error: ACMEv1 is deprecated and you can &#8230;</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/9107/certbot-error-acmev1-is-deprecated/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Certbot 申請 SSL certificate 錯誤問題</title>
		<link>https://noter.tw/8596/certbot-error/</link>
					<comments>https://noter.tw/8596/certbot-error/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Mon, 21 Jun 2021 15:36:28 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[.well-known]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[acme-challenge]]></category>
		<category><![CDATA[SSL For Free]]></category>
		<category><![CDATA[LetsEncrypt]]></category>
		<category><![CDATA[certbot]]></category>
		<category><![CDATA[certonly]]></category>
		<category><![CDATA[--dry-run]]></category>
		<category><![CDATA[The client lacks sufficient authorization]]></category>
		<category><![CDATA[Failed authorization procedure]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[--webroot]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Invalid response from]]></category>
		<category><![CDATA[certificate]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=8596</guid>

					<description><![CDATA[<p>今天幫好友處理 Certbot 的問題，這伺服器上已經申請過一個，這次要申請另一個域名，卻怎麼樣都會出現「The client lacks sufficient authorization」的錯誤，試&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/8596/certbot-error/" data-wpel-link="internal">Certbot 申請 SSL certificate 錯誤問題</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>今天幫好友處理 Certbot 的問題，這伺服器上已經申請過一個，這次要申請另一個域名，卻怎麼樣都會出現「The client lacks sufficient authorization」的錯誤，試了一些時間總算完成。</p>



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



<p>Certbot 真的是個方便的東西，記得很久以前小蛙架部落格剛要轉 https 的時候，還要去 <a href="https://www.sslforfree.com/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">SSL for Free 網站<span class="wpel-icon wpel-image wpel-icon-6"></span></a>手動申請及安裝(可參考<a href="https://noter.tw/?s=ssl+for+free" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">這邊</a>)，SSL for Free 的好處是申請 SSL 完全免費，但是有一個缺點是每三個月必須自己手動去更新(renew)，小蛙用了一段時間後發現，原來有 Certbot 這麼方便又好用的東西，之後有機會再來介紹這個，今天這篇只是要記錄使用 certbot 錯誤的解決方法。</p>



<p>是這樣的，在 Ubuntu 可以直接透過 certbot 申請 SSL 憑證，也包含了自動更新的功能，但是小蛙要申請一個新的網域的時候，卻發生了下列錯誤</p>



<pre class="wp-block-preformatted withcode">root@lc:/home/sysadm# certbot certonly --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Which names would you like to activate HTTPS for?
 
1: mydomain.com
 
Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel): 1

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mydomain.com
Waiting for verification…
Cleaning up challenges
Failed authorization procedure. mydomain.com (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://mydomain.com/.well-known/acme-challenge/xxxxxx [xxx.xxx.xxx.xxx]: "\n\n404 Not Found\n\n Not Found \n&lt;p"
 IMPORTANT NOTES:
 The following errors were reported by the server:
 Domain: mydomain.com
 Type:   unauthorized
 Detail: Invalid response from
 http://mydomain.com/.well-known/acme-challenge/xxxx
 [xxx.xxx.xxx.xxx]: "\n\n404 Not Found\n\n Not Found \n&lt;p"

To fix these errors, please make sure that your domain name was entered correctly and the DNS A/AAAA record(s) for that domain
contain(s) the right IP address.
Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. </pre>



<p>裡面看到幾個關鍵「Failed authorization procedure」、「unauthorized」、「Invalid response from」、「The client lacks sufficient authorization」</p>



<p>第一直覺是檔案連不到，但直接連 http://mydomain.com/.well-known/acme-challenge/xxxxxx 又沒有問題，看到朋友的主機有一堆奇怪的 site 設定檔，先清一清看看，嗯 ~ 好，沒有反應，錯誤還是存在。</p>



<p>一直發生上面的錯誤，不斷測試不斷重試，結果得到下面的錯誤 &#8230; (嗚嗚嗚)</p>



<pre class="wp-block-preformatted withcode">root@lc:/etc/apache2/sites-enabled# certbot --apache

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Which names would you like to activate HTTPS for?
 
 1: mydomain.com
 
Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel): 1

Obtaining a new certificate
An unexpected error occurred:
  There were too many requests of a given type :: Error creating new order :: too many failed authorizations recently: see https://letsencrypt.org/docs/rate-limits/
Please see the logfiles in /var/log/letsencrypt for more details.</pre>



<p>進去錯誤訊息給的<a href="https://letsencrypt.org/zh-tw/docs/rate-limits/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">連結<span class="wpel-icon wpel-image wpel-icon-6"></span></a>後，裡面有一段話寫著「我們還有<strong>網域驗證失敗</strong>限制，對於每個帳號每域名每小時 5 次的限制。在<a href="https://letsencrypt.org/zh-tw/docs/staging-environment/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">測試環境<span class="wpel-icon wpel-image wpel-icon-6"></span></a>中並沒有那麼嚴格的限制，因此你可以使用測試環境來針對連線問題除錯。」</p>



<p class="withcode">額外得知原來加了<code>--dry-run</code>就是測試環境，只會用來測試並不會真正儲存申請的憑證，而且限制比較沒那麼嚴格，如果是要測試為什麼申請失敗只要加上<code>--dry-run</code>，確定都沒有問題後才透過正式環境申請。小蛙這邊超過了每小時五次的限制，只能等到先用<code>--dry-run</code>來測試，等 unban 之後再到正式環境申請了。</p>



<p>經過重重困難後，決定一個參數一個參數試試看，於是試出了</p>



<pre class="wp-block-preformatted withcode">root@lc:/var/www/html# certbot certonly --webroot -w /var/www/html/ -d mydomain.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mydomain.com
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification…
Cleaning up challenges

IMPORTANT NOTES:
 Congratulations! Your certificate and chain have been saved at:
 /etc/letsencrypt/live/mydomain.com/fullchain.pem
 Your key file has been saved at:
 /etc/letsencrypt/live/mydomain.com/privkey.pem
 Your cert will expire on 2021-09-19. To obtain a new or tweaked
 version of this certificate in the future, simply run certbot
 again. To non-interactively renew <em>all</em> of your certificates, run
 "certbot renew"
 If you like Certbot, please consider supporting our work by:
 Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
 Donating to EFF: https://eff.org/donate-le </pre>



<p class="withcode">終於，加上了<code>--webroot -w /var/www/html/</code>之後就成功了 ~ 看起來可能是<code>.well-known/acme-challenge/xxxxxxx</code>的預設路徑不知道為什麼不在目前使用的目錄，導致驗證的時候會抓不到產生的驗證檔案而噴錯，加入該設定之後就完成了，這篇文章留給有需要的朋友 ~</p>



<p><strong>網站架設系列文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/10151/%e7%9b%a4%e9%bb%9e%e9%82%a3%e4%ba%9b%e6%9b%be%e7%b6%93%e9%99%aa%e4%bc%b4%e9%81%8e%e5%b0%8f%e8%9b%99%e7%9a%84-vps-%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f/" data-wpel-link="internal">盤點那些曾經陪伴過小蛙的 VPS 虛擬主機</a></li><li><a href="https://noter.tw/176/%e5%a6%82%e4%bd%95%e6%8c%91%e9%81%b8-vps-%e6%9c%80%e5%88%92%e7%ae%97%e7%9a%84%e8%b2%b7%e6%b3%95/" data-wpel-link="internal">如何挑選 VPS + 最划算的買法</a></li><li><a href="https://noter.tw/406/%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E5%A6%82%E4%BD%95%E8%B3%BC%E8%B2%B7-vps/" data-wpel-link="internal">手把手教你如何購買 VPS</a></li><li><a href="https://noter.tw/4463/第一次買-kvm-虛擬主機/" data-wpel-link="internal">第一次買 KVM 虛擬主機</a></li><li><a href="https://noter.tw/4242/%e8%a1%80%e7%9a%84%e6%95%99%e8%a8%93-hiformance-%e8%b7%91%e8%b7%af%e4%ba%86/" data-wpel-link="internal">血的教訓 &#8211; HiFormance 跑路了 &#8230;</a></li><li><a href="https://noter.tw/196/%e7%82%ba%e8%87%aa%e5%b7%b1%e7%94%b3%e8%ab%8b%e4%b8%80%e5%80%8b%e5%9f%9f%e5%90%8d-hinet-%e7%82%ba%e4%be%8b/" data-wpel-link="internal">為自己申請一個域名 – HiNet 為例</a></li><li><a href="https://noter.tw/117/cloudflare-%E8%B6%85%E5%BC%B7%E5%A4%A7%E7%9A%84%E5%85%8D%E8%B2%BB-cdn/" data-wpel-link="internal">Cloudflare – 超強大的免費 CDN (?)</a></li><li><a href="https://noter.tw/195/%e4%bd%bf%e7%94%a8-cloudflare-%e4%bb%a3%e7%ae%a1%e4%bd%a0%e7%9a%84%e5%9f%9f%e5%90%8d/" data-wpel-link="internal">使用 Cloudflare 代管你的域名</a></li><li><a href="https://noter.tw/396/ubuntu-16-04-設定環境語言編碼，讓中文可以正常顯示/" data-wpel-link="internal">Ubuntu 16.04 設定環境語言編碼，讓中文可以正常顯示</a></li><li><a href="https://noter.tw/255/ubuntu-16-04-%e5%ae%89%e8%a3%9d-fail2ban/" data-wpel-link="internal">Ubuntu 16.04 安裝 fail2ban</a></li><li><a href="https://noter.tw/436/%E4%B8%80%E5%80%8B%E8%85%B3%E6%9C%AC%E6%AF%8F%E5%A4%A9%E8%87%AA%E5%8B%95%E5%82%99%E4%BB%BD/" data-wpel-link="internal">一個腳本每天自動備份</a></li><li><a href="https://noter.tw/32/linux-tar-%E5%AE%8C%E6%95%B4%E5%82%99%E4%BB%BD%E3%80%81%E5%A2%9E%E9%87%8F%E5%82%99%E4%BB%BD%E5%8F%8A%E5%B7%AE%E7%95%B0%E5%82%99%E4%BB%BD%E6%AF%94%E8%BC%83/" data-wpel-link="internal">Linux tar 完整備份、增量備份及差異備份比較</a></li><li><a href="https://noter.tw/3704/nginx-ssl-certificate-%E8%AE%93-http-%E8%AE%8A%E8%BA%AB%E6%88%90%E7%82%BA-https/" data-wpel-link="internal">nginx + SSL Certificate – 讓 http 變身成為 https</a></li><li><a href="https://noter.tw/3695/ssl-for-free-%E5%85%8D%E8%B2%BB%E5%8F%88%E6%9C%89%E7%B6%A0%E8%89%B2%E9%8E%96%E9%A0%AD%E7%9A%84-ssl-certificates/" data-wpel-link="internal">SSL For Free – 免費又有綠色鎖頭的 SSL Certificates</a></li><li><a href="https://noter.tw/8596/certbot-error/" data-wpel-link="internal">Certbot 申請 SSL certificate 錯誤問題</a></li><li><a href="https://noter.tw/9107/certbot-error-acmev1-is-deprecated/" data-wpel-link="internal">Certbot 錯誤：ACMEv1 is deprecated and you can …</a></li><li><a href="https://noter.tw/5967/ubuntu-18-04-%e5%ae%89%e8%a3%9d-awstats-%e4%be%86%e7%b5%b1%e8%a8%88%e7%b6%b2%e7%ab%99%e6%b5%81%e9%87%8f/" data-wpel-link="internal">Ubuntu 18.04 安裝 AWStats 來統計網站流量</a></li><li><a href="https://noter.tw/9287/pchome-%e8%b2%b7%e7%b6%b2%e5%9d%80%e7%ba%8c%e7%b4%84%e6%b5%81%e7%a8%8b/" data-wpel-link="internal">PCHome 買網址續約流程</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/8596/certbot-error/" data-wpel-link="internal">Certbot 申請 SSL certificate 錯誤問題</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/8596/certbot-error/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ubuntu 18.04 安裝 AWStats 來統計網站流量</title>
		<link>https://noter.tw/5967/ubuntu-18-04-%e5%ae%89%e8%a3%9d-awstats-%e4%be%86%e7%b5%b1%e8%a8%88%e7%b6%b2%e7%ab%99%e6%b5%81%e9%87%8f/</link>
					<comments>https://noter.tw/5967/ubuntu-18-04-%e5%ae%89%e8%a3%9d-awstats-%e4%be%86%e7%b5%b1%e8%a8%88%e7%b6%b2%e7%ab%99%e6%b5%81%e9%87%8f/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sun, 20 Oct 2019 06:54:45 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<category><![CDATA[網頁後端]]></category>
		<category><![CDATA[AWStats]]></category>
		<category><![CDATA[網站資料統計]]></category>
		<category><![CDATA[網站流量]]></category>
		<category><![CDATA[網站分析]]></category>
		<category><![CDATA[流量統計]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[教學]]></category>
		<category><![CDATA[2019]]></category>
		<category><![CDATA[分享]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=5967</guid>

					<description><![CDATA[<p>最近接到一個任務，要用 AWStats 統計流量，之前大多使用 Google Analytics，這次要求用 AWStats，很久以前有用過，但從來沒有自己架設過，這篇留個紀錄。 安裝 AWStats&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/5967/ubuntu-18-04-%e5%ae%89%e8%a3%9d-awstats-%e4%be%86%e7%b5%b1%e8%a8%88%e7%b6%b2%e7%ab%99%e6%b5%81%e9%87%8f/" data-wpel-link="internal">Ubuntu 18.04 安裝 AWStats 來統計網站流量</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>最近接到一個任務，要用 AWStats 統計流量，之前大多使用 Google Analytics，這次要求用 AWStats，很久以前有用過，但從來沒有自己架設過，這篇留個紀錄。</p>



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



<h2 class="para wp-block-heading" id="install">安裝 AWStats</h2>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">sudo apt-get install awstats libgeo-ipfree-perl libnet-ip-perl</pre>



<p>這邊應該沒有什麼問題，安裝就是了。</p>



<h2 class="para wp-block-heading" id="config">設定要統計的網站</h2>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code"># 把預設的 awstats.conf 複製一份出來改
sudo cp /etc/awstats/awstats.conf /etc/awstats/awstats.noter.tw.conf
# 編輯設定檔
sudo vim /etc/awstats/awstats.noter.tw.conf</pre>



<p>安裝完之後在 /etc/awstats/ 下面會有一個預設設定檔 awstats.conf，直接複製出來改成 awstats.接上你的網址.conf，然後進入編輯。</p>



<p>要修改的部份小蛙直接參考 <a rel="noreferrer noopener nofollow external" aria-label="Awstats流量統計@Alvin Chen Club (在新分頁中開啟)" href="http://www.alvinchen.club/2018/04/14/awstats-%E8%AE%93%E4%BD%A0%E7%9F%A5%E9%81%93%E7%B6%B2%E7%AB%99%E6%B5%81%E9%87%8F%E6%9C%89%E5%A4%9A%E5%B0%91/" target="_blank" data-wpel-link="external" class="wpel-icon-right">Awstats流量統計@Alvin Chen Club<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 的設定</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code"># 要分析的 log 路徑，大概在 50 行左右
LogFile="/var/log/apache2/access.log"

# 記錄類別，維持不變 W = weblog，大概在 62 行
LogType=W

# 記錄格式，這邊小蛙的環境是 Apache2，維持 1 就好，也可以自己設定
# 大概在 123 行
LogFormat=1

# Domain，大概在 154 行
SiteDomain="noter.tw"

# 其他可連到主機的名稱，大概在 169 行
HostAliases="localhost 127.0.0.1"

AllowFullYearView=3
LoadPlugin="tooltips"
LoadPlugin="graphgooglechartapi"
LoadPlugin="geoipfree"</pre>



<p>小蛙大概改了這些東西，好了之後存檔離開。</p>



<h2 class="para wp-block-heading" id="mv">搬移排程檔</h2>



<p>因為剛安裝的時候，會自動在 /etc/cron.d/ 下面建立一個 awstats，打開可以看到裡面已經設定了自動執行的排程，為了避免等一下我們設定統計資料的時候，這個排程造成干擾，因此先把它移動到其他地方。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code"># 把 awstats 排程檔移動到其他地方放，e.g. /root 目錄下
sudo mv /etc/cron.d/awstats /root
# 把 awstats 裡面原本建立的檔案都先刪掉
sudo rm /var/lib/awstats/*</pre>



<h2 class="para wp-block-heading" id="manual">手動執行</h2>



<p>要知道設定檔能不能正確執行，就先手動跑一次囉！</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">sudo /usr/lib/cgi-bin/awstats.pl -config=noter.tw -update</pre>



<p>這一步小蛙跑超久超久，期間還一直被中斷 &#8230; 因為小蛙總共要跑 5 份統計資料，花了不少時間在這邊測試，後來發現很簡單，只要搭配這篇 <a href="https://noter.tw/3946/ssh-%e9%81%a0%e7%ab%af%e7%99%bb%e5%87%ba%e5%be%8c%e7%b9%bc%e7%ba%8c%e5%9f%b7%e8%a1%8c/" data-wpel-link="internal">SSH 遠端登出後繼續執行</a></p>



<p>感謝同事翻到這篇文章，並且了小蛙跑超久的解決方案</p>



<p class="pre left green">分析速度很慢的問題把 <strong>DNSLookup </strong>改成 <strong>0</strong> 應該就好了<br>官方文件有說 <br><strong>With DNSLookup enabled, log analyze speed is decreased by 40 to 100 times, so use it only if required</strong></p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code"># 使用 screen
screen

# 要執行的指令
sudo /usr/lib/cgi-bin/awstats.pl -config=noter.tw -update

# 離開 screen
ctrl + a, d</pre>



<p>這樣就會背景執行，突然斷線也不用擔心沒跑完，那要怎麼知道有沒有跑完呢？</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code"># 查看所有 screen
screen -ls

# 連到特定 screen (xxxx 是上面 -ls 出現的數字)
screen -r xxxx

# 如果看到 Found xxxx new qualified records. 的字樣，就可以關閉 screen
ctrl + a, k</pre>



<h2 class="para wp-block-heading" id="cron">設定排程檔</h2>



<p>跑完一次統計資料之後，就可以設定排程了，網路上看到的資料都是 10 分鐘跑一次，但是小蛙遇到的 case 跑一次要兩小時 &#8230; 十分鐘跑一次不就會後面卡一堆排程 &#8230; 在這邊花了一兩天測試。</p>



<p>除了跑很久的問題，還遇到指令的問題，例如這台主機已經有被其他人設定過 awstats，但是設定檔有問題造成無法正確執行；原本網站使用的<mark class="yellow">/usr/lib/cgi-bin/awstats.pl -update</mark>無法執行 &#8230;</p>



<p>先把剛剛移去 /root 下面放的 awstats 排程檔案移到 /etc/cron.d 下面放</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code"># 把排程檔移回
sudo mv /root/awstats /etc/cron.d

# 編輯排程檔
sudo vim /etc/cron.d/awstats

# 每天早上六點執行
0 6 * * * * root /usr/lib/cgi-bin/awstats.pl -config=noter.tw -update &gt; /dev/null</pre>



<p>小蛙的狀況如果沒有加上 -config=noter.tw 的話沒有辦法執行 Orz &#8230; 跟別人講的不一樣啊！總之加了好了，就加吧！想知道有沒有成功，可以先把運行時間調到三、五分鐘後，然後等他執行完再來看看有沒有。</p>



<h2 class="para wp-block-heading" id="apache">設定可以透過瀏覽器瀏覽</h2>



<p>編輯 <mark class="yellow">/etc/apache2/site-enabled/awstats.conf</mark> 加入以下設定</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon/ "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch</pre>



<h2 class="para wp-block-heading" id="restart">開啟模組，重啟 apache</h2>



<p>因為 awstats 是用 cgi 跑的，要開啟這個模組，開啟後重啟 apache</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">sudo a2enmod cgi
sudo service apache2 restart</pre>



<p>以上設定都沒問題的話，用瀏覽器開啟</p>



<pre class="left green">http://你的網址/cgi-bin/awstats.pl?config=上面設定的網址
</pre>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/YjQTx1CxHwnf6I4Kp7kGxE7wM3KzbYfBBMyOpUyxvTacRH5YXCfXtRlXYIphdGm5FvLJ-GAjSyvyPlajxMKrbKSpDmgfWww2m97LyUtWUiJeuuW9ynfEJyzAiSRVml5F0w5OvEoWBOMNuCRJvPp7I6WxvU1tAJuThg5f0KjuFGa0g-41QN2G1VAxE5afzMlxNqexHiLXF0U27ZHvn4wVluoaKXDBdjumToDB_t0CkYZTfLjdxgITRM8UYTYvn4113aUM9-E4YwEGFK8PPljEB-4h2BASaw_FVW9M2zmRCYaAu1CqutJacjF88UW-N6b6HaZl-Mn4oMSq6XHOhw56Jlp3DCCnqfZyadtDpR0gVn0YLfnPs2ZSl7lM8Q2qMhBgT7Bag4FizNSba4UizSfZlNyD4uljfvkBPt3CkHR19tsrktDEDIruw4sGjv16z1QXfWr2jW1QxLSQnBIzeQVyFtTrl3xKCLsjUFLP7RW-bfbRi-a9Ipn6RtayE8PLshbJtvjdP84gZsRRlvhecObIwKb7xX4iFYtwWmNnV8H9TVUmM3gVAFQUgPpqfMesroonqFrkg5lEgNXwJUHaJQQx3gyKuFfqnuPUjRHri6avnIIbKerNQhyCjpkj30SWUl2MPHZjy9zDesiMK1Y9xquNmTi8QozroOS2oVaa_3mTGk6ZgSSg-KTLtM5eM5l28ilSfzTR8zTQpnA_21tzu-Z-bRmfTBY6htDpQNgxjZgSgyjZV5pi=w901-h809-no" alt="YjQTx1CxHwnf6I4Kp7kGxE7wM3KzbYfBBMyOpUyxvTacRH5YXCfXtRlXYIphdGm5FvLJ GAjSyvyPlajxMKrbKSpDmgfWww2m97LyUtWUiJeuuW9ynfEJyzAiSRVml5F0w5OvEoWBOMNuCRJvPp7I6WxvU1tAJuThg5f0KjuFGa0g 41QN2G1VAxE5afzMlxNqexHiLXF0U27ZHvn4wVluoaKXDBdjumToDB t0CkYZTfLjdxgITRM8UYTYvn4113aUM9 E4YwEGFK8PPljEB 4h2BASaw FVW9M2zmRCYaAu1CqutJacjF88UW N6b6HaZl Mn4oMSq6XHOhw56Jlp3DCCnqfZyadtDpR0gVn0YLfnPs2ZSl7lM8Q2qMhBgT7Bag4FizNSba4UizSfZlNyD4uljfvkBPt3CkHR19tsrktDEDIruw4sGjv16z1QXfWr2jW1QxLSQnBIzeQVyFtTrl3xKCLsjUFLP7RW bfbRi a9Ipn6RtayE8PLshbJtvjdP84gZsRRlvhecObIwKb7xX4iFYtwWmNnV8H9TVUmM3gVAFQUgPpqfMesroonqFrkg5lEgNXwJUHaJQQx3gyKuFfqnuPUjRHri6avnIIbKerNQhyCjpkj30SWUl2MPHZjy9zDesiMK1Y9xquNmTi8QozroOS2oVaa 3mTGk6ZgSSg KTLtM5eM5l28ilSfzTR8zTQpnA 21tzu Z bRmfTBY6htDpQNgxjZgSgyjZV5pi=w901 h809 no Ubuntu 18.04 安裝 AWStats 來統計網站流量" title="Ubuntu 18.04 安裝 AWStats 來統計網站流量"></figure></div>



<h2 class="para wp-block-heading" id="secure">限制瀏覽</h2>



<p>如果不想讓其他人看到這個頁面的話，就必須要加上這一步限制瀏覽 &#8230; 先透過以下指令建立可登入的使用者帳號及密碼</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">sudo htpasswd -c /etc/apache2/htpasswd 要登入的帳號</pre>



<p>只要在剛剛編輯的 /etc/apache2/site-enabled/awstats.conf 加上</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">&lt;Directory "/usr/lib/cgi-bin/"&gt;
AuthUserFile /etc/apache2/htpasswd
AuthName "Please Enter Your Password"
AuthType Basic
Require valid-user
&lt;/Directory&gt;</pre>



<p>重新啟動 apache 就完成囉！</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/5967/ubuntu-18-04-%e5%ae%89%e8%a3%9d-awstats-%e4%be%86%e7%b5%b1%e8%a8%88%e7%b6%b2%e7%ab%99%e6%b5%81%e9%87%8f/" data-wpel-link="internal">Ubuntu 18.04 安裝 AWStats 來統計網站流量</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/5967/ubuntu-18-04-%e5%ae%89%e8%a3%9d-awstats-%e4%be%86%e7%b5%b1%e8%a8%88%e7%b6%b2%e7%ab%99%e6%b5%81%e9%87%8f/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>xmlrpc.php 被攻擊了！Nginx 一個設定擋掉 DoS / DDoS 攻擊</title>
		<link>https://noter.tw/5585/xmlrpc-php-%e8%a2%ab%e6%94%bb%e6%93%8a%e4%ba%86%ef%bc%81nginx-%e4%b8%80%e5%80%8b%e8%a8%ad%e5%ae%9a%e6%93%8b%e6%8e%89-dos-ddos-%e6%94%bb%e6%93%8a/</link>
					<comments>https://noter.tw/5585/xmlrpc-php-%e8%a2%ab%e6%94%bb%e6%93%8a%e4%ba%86%ef%bc%81nginx-%e4%b8%80%e5%80%8b%e8%a8%ad%e5%ae%9a%e6%93%8b%e6%8e%89-dos-ddos-%e6%94%bb%e6%93%8a/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sun, 01 Sep 2019 05:27:35 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[xmlrpc.xml]]></category>
		<category><![CDATA[攻擊]]></category>
		<category><![CDATA[資安]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[444]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[2019]]></category>
		<category><![CDATA[DoS]]></category>
		<category><![CDATA[DDoS]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=5585</guid>

					<description><![CDATA[<p>小蛙有一天在翻 log 的時候突然看到一堆存取 xmlrpc.php 的記錄，源源不絕的出現，Google 了一下解法，大概記錄一下。 問題 大概長這樣，源源不絕噴出來～ DoS / DDoS 在維基&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/5585/xmlrpc-php-%e8%a2%ab%e6%94%bb%e6%93%8a%e4%ba%86%ef%bc%81nginx-%e4%b8%80%e5%80%8b%e8%a8%ad%e5%ae%9a%e6%93%8b%e6%8e%89-dos-ddos-%e6%94%bb%e6%93%8a/" data-wpel-link="internal">xmlrpc.php 被攻擊了！Nginx 一個設定擋掉 DoS / DDoS 攻擊</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>小蛙有一天在翻 log 的時候突然看到一堆存取 xmlrpc.php 的記錄，源源不絕的出現，Google 了一下解法，大概記錄一下。</p>



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



<h3 class="para wp-block-heading">問題</h3>



<p>大概長這樣，源源不絕噴出來～</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/3KDFhEgXQqV5xnNddnU6EPEcXtoInEIEbA31OLz9g6stnHLfFmyuE1URoS6jSROzERmftu7cnqoO5z-0w5xktXpbHLuuLnSKcB0EZ40oReXqOEAkcoHeysUwpJ0mrVvHNHheK9ks3olq3evrG0plAzDYbFOP0MWotxarthexkemsfJFl9zhAkVIrCeBRDnpJ3v-k64E7iMbO8PdfokSIKqJaRBbzNCFjeUtylEF0SsQA1NAQnMCKrYOT7kAvXODGVYu76MiG64ASeaWqmCRSWFKQ-tMORASab7e2cif3iKsca1vUa0nTxmekt19WTanDPKMHFYfWBaGEfciyEiupjewFVF639tP0CZANwn7_Ya4fjztdVBqRmPdVfi_1HRI1A-L3R4sVHj30-0d4eKm9fXuS_pRpGdJUdw9tjbOhAAbVzNWi-Di1zx1GLr7ViDUgi04cQsB1XU8fxfJUmU1vzoTzR2IyfUTP2kfQAT6twlg_FZ2W1fKr8RAcSdiY-o9QjDZ9aUxT2OU-mBtYxdcXOujdrnGye8Vf0WWhKzNRlc7EtuITpnI1GPlkcdTdiC5keGyT93OmuRyacmvVBoub69OSo2pxhVu2cVridwDo-roW3f-DnVS-j7jAY8qajjBnYlpZ-vL_XLo1WNJaJ9ECWc-IgPcaJdjJMSrSVQVKyVMogOj28yegowLFNkG0T7FIG8HHBc0SjETi2q1qLLU5TEM5Hw=w1383-h984-no" alt="3KDFhEgXQqV5xnNddnU6EPEcXtoInEIEbA31OLz9g6stnHLfFmyuE1URoS6jSROzERmftu7cnqoO5z 0w5xktXpbHLuuLnSKcB0EZ40oReXqOEAkcoHeysUwpJ0mrVvHNHheK9ks3olq3evrG0plAzDYbFOP0MWotxarthexkemsfJFl9zhAkVIrCeBRDnpJ3v k64E7iMbO8PdfokSIKqJaRBbzNCFjeUtylEF0SsQA1NAQnMCKrYOT7kAvXODGVYu76MiG64ASeaWqmCRSWFKQ tMORASab7e2cif3iKsca1vUa0nTxmekt19WTanDPKMHFYfWBaGEfciyEiupjewFVF639tP0CZANwn7 Ya4fjztdVBqRmPdVfi 1HRI1A L3R4sVHj30 0d4eKm9fXuS pRpGdJUdw9tjbOhAAbVzNWi Di1zx1GLr7ViDUgi04cQsB1XU8fxfJUmU1vzoTzR2IyfUTP2kfQAT6twlg FZ2W1fKr8RAcSdiY o9QjDZ9aUxT2OU mBtYxdcXOujdrnGye8Vf0WWhKzNRlc7EtuITpnI1GPlkcdTdiC5keGyT93OmuRyacmvVBoub69OSo2pxhVu2cVridwDo roW3f DnVS j7jAY8qajjBnYlpZ vL XLo1WNJaJ9ECWc IgPcaJdjJMSrSVQVKyVMogOj28yegowLFNkG0T7FIG8HHBc0SjETi2q1qLLU5TEM5Hw=w1383 h984 no xmlrpc.php 被攻擊了！Nginx 一個設定擋掉 DoS / DDoS 攻擊" title="xmlrpc.php 被攻擊了！Nginx 一個設定擋掉 DoS / DDoS 攻擊"></figure></div>



<p>DoS / DDoS 在維基百科的翻譯是</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p><strong>阻斷服務攻擊</strong>（英語：denial-of-service attack，簡稱<strong>DoS攻擊</strong>）亦稱<strong>洪水攻擊</strong>，是一種<a href="https://zh.wikipedia.org/wiki/%E7%B6%B2%E7%B5%A1%E6%94%BB%E6%93%8A" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external" class="wpel-icon-right">網路攻擊<span class="wpel-icon wpel-image wpel-icon-6"></span></a>手法，其目的在於使目標電腦的<a href="https://zh.wikipedia.org/wiki/%E7%B6%B2%E9%9A%9B%E7%B6%B2%E8%B7%AF" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external" class="wpel-icon-right">網路<span class="wpel-icon wpel-image wpel-icon-6"></span></a>或<a href="https://zh.wikipedia.org/wiki/%E7%B3%BB%E7%B5%B1" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external" class="wpel-icon-right">系統<span class="wpel-icon wpel-image wpel-icon-6"></span></a>資源耗盡，使服務暫時中斷或停止，導致其正常用戶無法存取。<br>當<a href="https://zh.wikipedia.org/wiki/%E9%BB%91%E5%AE%A2" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external" class="wpel-icon-right">駭客<span class="wpel-icon wpel-image wpel-icon-6"></span></a>使用網路上兩個或以上被攻陷的電腦作為「<a href="https://zh.wikipedia.org/wiki/%E6%AE%AD%E5%B1%8D%E9%9B%BB%E8%85%A6" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external" class="wpel-icon-right">殭屍<span class="wpel-icon wpel-image wpel-icon-6"></span></a>」向特定的目標發動「阻斷服務」式攻擊時，稱為<strong>分散式阻斷服務攻擊</strong>（distributed denial-of-service attack，簡稱<strong>DDoS攻擊</strong>）。 </p><cite><a href="https://zh.wikipedia.org/wiki/%E9%98%BB%E6%96%B7%E6%9C%8D%E5%8B%99%E6%94%BB%E6%93%8A" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external" class="wpel-icon-right">阻斷服務攻擊<span class="wpel-icon wpel-image wpel-icon-6"></span></a></cite></blockquote>



<h3 class="para wp-block-heading">解決方法</h3>



<p>小蛙有掛 Cloudflare CDN，標榜可以擋掉一些 DoS / DDoS，不過 log 裡還是能看到一大堆記錄，小蛙參考了兩篇文章，基本做法都差不多。</p>



<p>第一篇參考自 <a rel="noreferrer noopener nofollow external" aria-label="Deny Access to WordPress xmlrpc.php with NGINX (在新分頁中開啟)" href="http://www.jeedo.net/deny-access-to-wordpress-xmlrpc-php-with-nginx/" target="_blank" data-wpel-link="external" class="wpel-icon-right">Deny Access to WordPress xmlrpc.php with NGINX<span class="wpel-icon wpel-image wpel-icon-6"></span></a><br>第二篇參考自 <a rel="noreferrer noopener nofollow external" aria-label="資安：WordPress 禁止 xmlrpc.php 攻擊 (在新分頁中開啟)" href="https://shazi.info/%E8%B3%87%E5%AE%89%EF%BC%9Awordpress-%E7%A6%81%E6%AD%A2-xmlrpc-php-%E6%94%BB%E6%93%8A/" target="_blank" data-wpel-link="external" class="wpel-icon-right">資安：WordPress 禁止 xmlrpc.php 攻擊<span class="wpel-icon wpel-image wpel-icon-6"></span></a> </p>



<p>從 WordPress 3.5 以後，xmlrpc 預設是開啟的，記得很久以前小蛙的主機也被密集攻擊過一次</p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://lh3.googleusercontent.com/FhKs2UkzZvIaSjWZKS-amd5_dI-4uTeDohDkNOrRufWfiDkI9074_DADh7civNpwc3DdwmFInZ5gfcb9HZZkIDdtsgZ_WhgdHsl48MlRF9d2X8YFmTQ8eJu3Nd4ahHr4whSW4KAwyga-v45WD0U04bebwkhSFuM7Q2qehETsKzkJYDkDRbB88Jx-rs4_23btd4j2K2Jn9_zDWXeQiC6Dt9VjMQN-aKk8n68Tov0qJhh8Xi0txJeX5dz96wd-2OQd3YuDdoF1uTjCyX_ggGH5QW5s9LX2CnxGv2jYkKmRLJeamrXu8pM9uF116WDT6IO32dDK_5g2vp37G02o_99NPFWBittYcrYq5tMjeGfc6idyxOrdPGw6Y45B-pEBmXFkWOct__qAwFwtgF5DdVSc7_VgEJfN_JD98wBK3OtkR0m1idQAamgL2jkAmNiLG8tKdVkJKvy3yNnm1hNALzQrZYPTg1Nuonsnza0eKWdYLv68WWr3gvB6GG3xLGhGaky3PsS-BsDNJShWdZ-wM9bcNL-7C2CD_FXZA2HN75jn3VAqlB2Psm34Oznn8MVK63npxXnyNFnwNkudmK9DMrKhlcEn3av63SCNkQAJKQdEQLZad0ULMYMQOUDthedJNKJr3winGh1xBCddplRfn9BOu5tCKiNJoxJgjbETj89BOc8_fkxgREFq1e3GHzBE9LxkzT-ePd0zBZ7ZY7vlnZVAN_uCOxFFu7F9Ublv2tEM7Z0U0xw3=w652-h148-no" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external"><img decoding="async" src="https://lh3.googleusercontent.com/FhKs2UkzZvIaSjWZKS-amd5_dI-4uTeDohDkNOrRufWfiDkI9074_DADh7civNpwc3DdwmFInZ5gfcb9HZZkIDdtsgZ_WhgdHsl48MlRF9d2X8YFmTQ8eJu3Nd4ahHr4whSW4KAwyga-v45WD0U04bebwkhSFuM7Q2qehETsKzkJYDkDRbB88Jx-rs4_23btd4j2K2Jn9_zDWXeQiC6Dt9VjMQN-aKk8n68Tov0qJhh8Xi0txJeX5dz96wd-2OQd3YuDdoF1uTjCyX_ggGH5QW5s9LX2CnxGv2jYkKmRLJeamrXu8pM9uF116WDT6IO32dDK_5g2vp37G02o_99NPFWBittYcrYq5tMjeGfc6idyxOrdPGw6Y45B-pEBmXFkWOct__qAwFwtgF5DdVSc7_VgEJfN_JD98wBK3OtkR0m1idQAamgL2jkAmNiLG8tKdVkJKvy3yNnm1hNALzQrZYPTg1Nuonsnza0eKWdYLv68WWr3gvB6GG3xLGhGaky3PsS-BsDNJShWdZ-wM9bcNL-7C2CD_FXZA2HN75jn3VAqlB2Psm34Oznn8MVK63npxXnyNFnwNkudmK9DMrKhlcEn3av63SCNkQAJKQdEQLZad0ULMYMQOUDthedJNKJr3winGh1xBCddplRfn9BOu5tCKiNJoxJgjbETj89BOc8_fkxgREFq1e3GHzBE9LxkzT-ePd0zBZ7ZY7vlnZVAN_uCOxFFu7F9Ublv2tEM7Z0U0xw3=w652-h148-no" alt="FhKs2UkzZvIaSjWZKS amd5 dI 4uTeDohDkNOrRufWfiDkI9074 DADh7civNpwc3DdwmFInZ5gfcb9HZZkIDdtsgZ WhgdHsl48MlRF9d2X8YFmTQ8eJu3Nd4ahHr4whSW4KAwyga v45WD0U04bebwkhSFuM7Q2qehETsKzkJYDkDRbB88Jx rs4 23btd4j2K2Jn9 zDWXeQiC6Dt9VjMQN aKk8n68Tov0qJhh8Xi0txJeX5dz96wd 2OQd3YuDdoF1uTjCyX ggGH5QW5s9LX2CnxGv2jYkKmRLJeamrXu8pM9uF116WDT6IO32dDK 5g2vp37G02o 99NPFWBittYcrYq5tMjeGfc6idyxOrdPGw6Y45B pEBmXFkWOct qAwFwtgF5DdVSc7 VgEJfN JD98wBK3OtkR0m1idQAamgL2jkAmNiLG8tKdVkJKvy3yNnm1hNALzQrZYPTg1Nuonsnza0eKWdYLv68WWr3gvB6GG3xLGhGaky3PsS BsDNJShWdZ wM9bcNL 7C2CD FXZA2HN75jn3VAqlB2Psm34Oznn8MVK63npxXnyNFnwNkudmK9DMrKhlcEn3av63SCNkQAJKQdEQLZad0ULMYMQOUDthedJNKJr3winGh1xBCddplRfn9BOu5tCKiNJoxJgjbETj89BOc8 fkxgREFq1e3GHzBE9LxkzT ePd0zBZ7ZY7vlnZVAN uCOxFFu7F9Ublv2tEM7Z0U0xw3=w652 h148 no xmlrpc.php 被攻擊了！Nginx 一個設定擋掉 DoS / DDoS 攻擊" title="xmlrpc.php 被攻擊了！Nginx 一個設定擋掉 DoS / DDoS 攻擊"></a></figure></div>



<p>小蛙用的是 nginx，裡面可以設定當某個路徑被存取的時候，作相對應的動作，這邊我們確切知道就是 /xmlrpc.php 這支，所以就可以這樣寫</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">server {
  ...
  location = /xmlrpc.php {
    deny all;
    access_log off;
    log_not_found off;
    return 444; 
  }
}</pre>



<p>當被存取 xmlrpc.php 的時候，拒絕所有連線，把存取 log 跟找不到檔案 log 都關掉，最後回傳 444，而這個 444 <a href="https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81" target="_blank" rel="noreferrer noopener nofollow external" aria-label="維基百科 (在新分頁中開啟)" data-wpel-link="external" class="wpel-icon-right">維基百科<span class="wpel-icon wpel-image wpel-icon-6"></span></a>上的說明是 nginx 自己擴充的狀態碼。</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/XJ4orO2MZsURjfU6TrmCzHWPBR6Uq3ZS66qmx2iAuiqpZ33AIuLM1BngtEQK1pQx43p5XfPHYYjAWdzrAEk1typzGm2tcd32w6JWMs8ipNGdO8O2PqYzC82t-6L2fTCZ-ciy5sdZPOPivObmh-ga58BPeFzB8uuxzgL10RfVxHH4dc9vIBXO3Q8ZFR7yhkQ_nbe32Ve9BO5KX078TCz_H9ZszFaO7jPQdsg31m9-r55Q20sXIhAR3swpvWfW4HZFXe-J_8b9_nwURLU5lpg6eVREE-hXBJ1naGu_3z_GDzWGgOSgBWVSFCoqHY4lvx4n8rfu-QiJ84T6LK_AVxmruKinFCdwxIUwRHYMWoKHeHr-lT-SCakPKtIp5-Mi0qqhU3fotJHCjChzJbAlpjJUsckRuSVUFs6mHcc7hIm0ut6Nb6WYuC8kS0nf7unfV2AE1XnZxOxL6VedEsc2qK_J4e9fZ6B1ZIDwwvk1ZinOpl692jpdLz2BF8ly3IdmQaSy68HTfLJWCNrNPbJcKGfjatVuMvFcmM-Qbm5VHPzmbqQndV23371HAzjYcsib180DEQGk8SiUDUQttx34vlEqb6lh2YdgNviXHzhWh7D50r-hMXqQWg0yHMbztGUCD_OluQ9fVpUJczjIBU2ZPi15ePHowLrJhl_DvLYftCrsb6IzR_BCpPUx0bgP7fxRaOAMG8a_cDQuqHw3wxdHVMh1w_0H2w=w888-h332-no" alt="XJ4orO2MZsURjfU6TrmCzHWPBR6Uq3ZS66qmx2iAuiqpZ33AIuLM1BngtEQK1pQx43p5XfPHYYjAWdzrAEk1typzGm2tcd32w6JWMs8ipNGdO8O2PqYzC82t 6L2fTCZ ciy5sdZPOPivObmh ga58BPeFzB8uuxzgL10RfVxHH4dc9vIBXO3Q8ZFR7yhkQ nbe32Ve9BO5KX078TCz H9ZszFaO7jPQdsg31m9 r55Q20sXIhAR3swpvWfW4HZFXe J 8b9 nwURLU5lpg6eVREE hXBJ1naGu 3z GDzWGgOSgBWVSFCoqHY4lvx4n8rfu QiJ84T6LK AVxmruKinFCdwxIUwRHYMWoKHeHr lT SCakPKtIp5 Mi0qqhU3fotJHCjChzJbAlpjJUsckRuSVUFs6mHcc7hIm0ut6Nb6WYuC8kS0nf7unfV2AE1XnZxOxL6VedEsc2qK J4e9fZ6B1ZIDwwvk1ZinOpl692jpdLz2BF8ly3IdmQaSy68HTfLJWCNrNPbJcKGfjatVuMvFcmM Qbm5VHPzmbqQndV23371HAzjYcsib180DEQGk8SiUDUQttx34vlEqb6lh2YdgNviXHzhWh7D50r hMXqQWg0yHMbztGUCD OluQ9fVpUJczjIBU2ZPi15ePHowLrJhl DvLYftCrsb6IzR BCpPUx0bgP7fxRaOAMG8a cDQuqHw3wxdHVMh1w 0H2w=w888 h332 no xmlrpc.php 被攻擊了！Nginx 一個設定擋掉 DoS / DDoS 攻擊" title="xmlrpc.php 被攻擊了！Nginx 一個設定擋掉 DoS / DDoS 攻擊"></figure></div>



<p>雖然這樣 request 還是會進來，但是至少被 nginx 拒絕掉之後，不會因為大量執行 php，導致占用 CPU 跟記憶體，另外 <a rel="noreferrer noopener nofollow external" href="http://www.jeedo.net/deny-access-to-wordpress-xmlrpc-php-with-nginx/" target="_blank" data-wpel-link="external" class="wpel-icon-right">Deny Access to WordPress xmlrpc.php with NGINX<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 最下面也有提到，用這個方法的話，會導致一些需要透過外部存取的插件失效，不過小蛙沒有用類似的套件，先解燃眉之急囉！這篇留在這邊給有需要的人或是未來換主機之後又遇到的自己。</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/5585/xmlrpc-php-%e8%a2%ab%e6%94%bb%e6%93%8a%e4%ba%86%ef%bc%81nginx-%e4%b8%80%e5%80%8b%e8%a8%ad%e5%ae%9a%e6%93%8b%e6%8e%89-dos-ddos-%e6%94%bb%e6%93%8a/" data-wpel-link="internal">xmlrpc.php 被攻擊了！Nginx 一個設定擋掉 DoS / DDoS 攻擊</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/5585/xmlrpc-php-%e8%a2%ab%e6%94%bb%e6%93%8a%e4%ba%86%ef%bc%81nginx-%e4%b8%80%e5%80%8b%e8%a8%ad%e5%ae%9a%e6%93%8b%e6%8e%89-dos-ddos-%e6%94%bb%e6%93%8a/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ubuntu 取消 Apache 2.4 的 TLSv1.0 教學</title>
		<link>https://noter.tw/4812/ubuntu-18-04-%e7%92%b0%e5%a2%83%e4%b8%8b%e5%8f%96%e6%b6%88-apache-2-4-%e7%9a%84-tlsv1-0-%e6%95%99%e5%ad%b8/</link>
					<comments>https://noter.tw/4812/ubuntu-18-04-%e7%92%b0%e5%a2%83%e4%b8%8b%e5%8f%96%e6%b6%88-apache-2-4-%e7%9a%84-tlsv1-0-%e6%95%99%e5%ad%b8/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Fri, 03 May 2019 16:35:48 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<category><![CDATA[關閉 SSLv3]]></category>
		<category><![CDATA[只允許 TLSv1.2]]></category>
		<category><![CDATA[SSLProtocol 設定]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[TLSv1.0]]></category>
		<category><![CDATA[LetsEncrypt]]></category>
		<category><![CDATA[2019]]></category>
		<category><![CDATA[關閉 TLSv1]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=4812</guid>

					<description><![CDATA[<p>突然接到一個求救，資安掃描的時候掃出 TLSv1.0 應該要關閉的漏洞，就開始 Google 要怎麼設定，Apache 小蛙不熟，通常都是問題來一個找一個解一個，來兩個找兩個解一雙 ~ 這篇記錄留給有&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/4812/ubuntu-18-04-%e7%92%b0%e5%a2%83%e4%b8%8b%e5%8f%96%e6%b6%88-apache-2-4-%e7%9a%84-tlsv1-0-%e6%95%99%e5%ad%b8/" data-wpel-link="internal">Ubuntu 取消 Apache 2.4 的 TLSv1.0 教學</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>突然接到一個求救，資安掃描的時候掃出 TLSv1.0 應該要關閉的漏洞，就開始 Google 要怎麼設定，Apache 小蛙不熟，通常都是問題來一個找一個解一個，來兩個找兩個解一雙 ~ 這篇記錄留給有需要的人。</p>



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



<p>這問題直接丟 Google 會有很多很多一拖拉庫的解法，不過有些應該是 CentOS 或是其他版本的，小蛙看 Ubuntu 18.04 + Apache 2.4 的路徑在 /etc/apache2/，跟網路上很多教學裡提到的 /etc/httpd/ 不一樣，就 ~ 都試試看吧。</p>



<p>終於看到一篇好像不錯 <a href="https://www.cloudibee.com/disabling-tls-apache/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Disabling TLS 1.0 on Apache web servers<span class="wpel-icon wpel-image wpel-icon-6"></span></a>，嗯嗯，路徑不同，不過既然知道要修改的屬性名稱叫做「SSLProtocol」，那就到小蛙的目錄 /etc/apache2/ 來搜尋一下</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">$ cd /etc/apache2/
$ grep -ir "SSLProtocol" *
mods-available/ssl.conf:        SSLProtocol all -SSLv3</pre>



<p>Bingo! 找到在模組資料夾中的 ssl.conf，動手改掉他吧！小蛙收到的需求是把 1.0 跟 1.1 關閉，保留 1.2 即可，因此把上面的 <code>SSLProtocol all -SSLv3</code> 改成 <code>SSLProtocol TLSv1.2</code>，改好之後 sudo service apache2 restart，立馬到 <a href="https://www.sslshopper.com/ssl-checker.html" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">SSL Checker<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 測試看看，結果 &#8230; 竟然沒生效 @@</p>



<p>左查右查，會不會是上面的網站 cache 呢？下指令查查看</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">$ nmap --script ssl-enum-ciphers -p 443 ip或domain | grep TLSv
|   TLSv1.0:
|   TLSv1.1:
|   TLSv1.2:</pre>



<p>我的天啊 ~ 真的沒生效 &#8230; (如果沒有安裝的話可以先 apt-get install nmap 來安裝這個套件)，查了很多 stackoverflow 終於找到這篇 <a href="https://stackoverflow.com/a/55282453/1227342" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Disabling TLS 1.0 in Apache 2.4<span class="wpel-icon wpel-image wpel-icon-6"></span></a>，原來設定有成功，只是因為小蛙使用了 letsencrypt 的免費 SSL，造成 Apache 載入 SSL 設定的時候，會被較後面載入的 letsencrypt 設定檔蓋掉，因此前面的 ssl.conf 才會設定了但沒有效果。把剛剛上面的設定檔設定到 /etc/letsencrypt/options-ssl-apache.conf 看看吧！</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">$ nmap --script ssl-enum-ciphers -p 443 ip或domain | grep TLSv
|   TLSv1.2:</pre>



<p>打完收工，太感謝 stackoverflow 的那個答案了，真的好想幫他按讚，可惜小蛙的積分不夠 &gt;..&lt;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/4812/ubuntu-18-04-%e7%92%b0%e5%a2%83%e4%b8%8b%e5%8f%96%e6%b6%88-apache-2-4-%e7%9a%84-tlsv1-0-%e6%95%99%e5%ad%b8/" data-wpel-link="internal">Ubuntu 取消 Apache 2.4 的 TLSv1.0 教學</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/4812/ubuntu-18-04-%e7%92%b0%e5%a2%83%e4%b8%8b%e5%8f%96%e6%b6%88-apache-2-4-%e7%9a%84-tlsv1-0-%e6%95%99%e5%ad%b8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>使用 Tuckey 讓舊版 Tomcat 也能 URLRewrite</title>
		<link>https://noter.tw/125/%e4%bd%bf%e7%94%a8-tuckey-%e8%ae%93%e8%88%8a%e7%89%88-tomcat-%e4%b9%9f%e8%83%bd-urlrewrite/</link>
					<comments>https://noter.tw/125/%e4%bd%bf%e7%94%a8-tuckey-%e8%ae%93%e8%88%8a%e7%89%88-tomcat-%e4%b9%9f%e8%83%bd-urlrewrite/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Wed, 26 Sep 2018 15:27:56 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=125</guid>

					<description><![CDATA[<p>這篇是小蛙犯蠢得到的結果，做都做了就順便記錄下來。 手邊得到一個需求是在 tomcat 下進行改寫網址的功能，也就是把 https://www.abc.com/def/ijk.jsp?type=xyz&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/125/%e4%bd%bf%e7%94%a8-tuckey-%e8%ae%93%e8%88%8a%e7%89%88-tomcat-%e4%b9%9f%e8%83%bd-urlrewrite/" data-wpel-link="internal">使用 Tuckey 讓舊版 Tomcat 也能 URLRewrite</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>這篇是小蛙犯蠢得到的結果，做都做了就順便記錄下來。</p>



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



<p>手邊得到一個需求是在 tomcat 下進行改寫網址的功能，也就是把</p>



<pre class="wp-block-preformatted">https://www.abc.com/def/ijk.jsp?type=xyz</pre>



<p>改寫成這種漂亮的</p>



<pre class="wp-block-preformatted">https://www.abc.com/def/xyz</pre>



<h2 class="wp-block-heading">啟用 Tuckey 步驟</h2>



<p>大概搜尋了一下之後發現 Tomcat 8.0 以下沒有辦法直接使用 urlrewrite 功能，只好用 tuckey 來做 urlrewrite 功能，跟著 <a href="https://cdn.rawgit.com/paultuckey/urlrewritefilter/master/src/doc/manual/4.0/index.html" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">官方文件<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 做就可以完成了，這邊小蛙還是大概記錄一下。</p>



<p>1. 到 <a href="https://cdn.rawgit.com/paultuckey/urlrewritefilter/master/src/doc/manual/4.0/index.html" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Tuckey 官方文件<span class="wpel-icon wpel-image wpel-icon-6"></span></a>，點選 Download 下載 <code>urlrewritefilter-4.0.3.jar</code><br>2. 將該 jar 放在 tomcat_project/WEB-INF/lib/ 資料夾中<br>3. 編輯 WEB-INF/web.xml 文件，如果沒有的話就建立一個，加入以下內容 </p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;filter>
  &lt;filter-name>UrlRewriteFilter&lt;/filter-name>
  &lt;filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter&lt;/filter-class>
&lt;/filter>
&lt;filter-mapping>
  &lt;filter-name>UrlRewriteFilter&lt;/filter-name>
  &lt;url-pattern>/*&lt;/url-pattern> 
  &lt;dispatcher>REQUEST&lt;/dispatcher> 
  &lt;dispatcher>FORWARD&lt;/dispatcher>
&lt;/filter-mapping></pre>



<p>4. 建立 WEB-INF/urlrewrite.xml，可直接下載範例：<a href="https://cdn.rawgit.com/paultuckey/urlrewritefilter/master/src/doc/manual/4.0/urlrewrite.xml" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">urlrewrite.xml<span class="wpel-icon wpel-image wpel-icon-6"></span></a><br>5. 重新啟動 tomcat 就完成了</p>



<h2 class="para wp-block-heading">URLRewrite 設定範例</h2>



<p>重啟 tomcat 沒有出現錯誤的話，就表示已經安裝成功，可以開始在<code>urlrewrite.xml</code>檔案中添加自己的規則了，上面下載的官方範例檔或官方說明文件中已經列出幾種常用的範例，以下僅節錄部份：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?xml version="1.0" encoding="utf-8"?>
&lt;!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN" "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
  &lt;urlrewrite>
    &lt;rule>
      &lt;note>
        The rule means that requests to /test/status/ will be redirected to /rewrite-status the url will be rewritten. 概念就是從 from 對應到 to，如果有 redirect 就會重新導向，瀏覽器上面的網址會變 &lt;/note>
      &lt;from>/test/status/&lt;/from>
      &lt;to type="redirect">%{context-path}/rewrite-status&lt;/to>
    &lt;/rule>
    &lt;rule>
      &lt;note>
        Redirect one url，重新導向一個頁面 
	  &lt;/note>
      &lt;from>/some/old/page.html&lt;/from>
      &lt;to type="redirect">/very/new/page.html&lt;/to>
    &lt;/rule>
    &lt;rule>
      &lt;note>
        Redirect a directory，重新導向一個資料夾 
	  &lt;/note>
      &lt;from>/some/olddir/(.*)&lt;/from>
      &lt;to type="redirect">/very/newdir/$1&lt;/to>
    &lt;/rule>
    &lt;rule>
      &lt;note>
        Clean a url，清理 URL eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing. 
	  &lt;/note>
      &lt;from>/products/([0-9]+)&lt;/from>
      &lt;to>/products/index.jsp?product_id=$1&lt;/to>
    &lt;/rule>
  &lt;/urlrewrite></pre>



<h2 class="para wp-block-heading">清理 URL 設定</h2>



<p>小蛙這邊希望做的事情是把上面提到的好看的網址，內部轉到有網頁名稱( xxx.jsp )跟問號( ? )的網址，對使用者來說是輸入好看的網址，醜的網址由 tuckey 內部處理對應關係隱藏起來。以小蛙的例子來說，原本的網址是<code>https://abc.com/web/javascripts/pdfjs/viewer.jsp?f=106project</code>，那小蛙接到的需求是希望能簡化成<code>https://abc.com/web/project</code>，所以外部連進來是沒有問號的好看的網址，而內部對應維有問號的網址，因此設定寫成：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;rule>
 &lt;from>^/web/([0-9a-zA-Z_]+)$&lt;/from>
 &lt;to>/web/javascripts/pdfjs/viewer.jsp?f=$1&lt;/to>
&lt;/rule></pre>



<p>其中<code>$1</code>會替換成 from 中 () 內的內容，至於為什麼文章一開頭會說小蛙犯蠢呢？因為小蛙的同事劈頭就問了，那台伺服器上面不是有 nginx 嗎？直接用 nginx 導向就好了 &#8230; ㄜ ~ 一點也沒錯，用 nginx 反而簡單些 &#8230; Tuckey 附的範例檔在小蛙需要的 Clean a url 的例子中，一直設定不起來，小蛙找了好久才發現，範例文件 from 部份寫<code>/prodocts/([0-9]+)</code>，但在新版的文件中的範例卻是<code>^/products/([0-9]+)</code>，在前面多加一個<code>^</code>就可以正常運作了 </p>



<h2 class="para wp-block-heading">參考資料</h2>



<p class="my-li bg-darkblue">1. <a href="https://stackoverflow.com/questions/25873406/urlrewrite-in-tomcat-7" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">URLRewrite in Tomcat 7<span class="wpel-icon wpel-image wpel-icon-6"></span></a><br>2.&nbsp;<a href="https://cdn.rawgit.com/paultuckey/urlrewritefilter/master/src/doc/manual/4.0/index.html" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">UrlRewriteFilter 4.0.3<span class="wpel-icon wpel-image wpel-icon-6"></span></a></p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/125/%e4%bd%bf%e7%94%a8-tuckey-%e8%ae%93%e8%88%8a%e7%89%88-tomcat-%e4%b9%9f%e8%83%bd-urlrewrite/" data-wpel-link="internal">使用 Tuckey 讓舊版 Tomcat 也能 URLRewrite</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/125/%e4%bd%bf%e7%94%a8-tuckey-%e8%ae%93%e8%88%8a%e7%89%88-tomcat-%e4%b9%9f%e8%83%bd-urlrewrite/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<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[virtualhost]]></category>
		<category><![CDATA[a2ensite]]></category>
		<category><![CDATA[a2query]]></category>
		<category><![CDATA[a2dissite]]></category>
		<category><![CDATA[Ubuntu]]></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>
		<item>
		<title>調整 php 版本</title>
		<link>https://noter.tw/3970/%e8%aa%bf%e6%95%b4-php-%e7%89%88%e6%9c%ac/</link>
					<comments>https://noter.tw/3970/%e8%aa%bf%e6%95%b4-php-%e7%89%88%e6%9c%ac/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 11:25:05 +0000</pubDate>
				<category><![CDATA[網頁後端]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[update-alternatives]]></category>
		<guid isPermaLink="false">https://wazai.net/?p=3970</guid>

					<description><![CDATA[<p>接續昨天處理的 swoole 編譯並且成功載入模組，今天朋友突然跟我說原本可以跑的 code 突然不能跑了 &#8230; 這就神奇了 ~~其實小蛙根本不清楚為什麼原本可以執行後來不能執行，也是因為小&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3970/%e8%aa%bf%e6%95%b4-php-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">調整 php 版本</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[<p>接續昨天處理的 swoole 編譯並且成功載入模組，今天朋友突然跟我說原本可以跑的 code 突然不能跑了 &#8230; 這就神奇了 ~~<br /><span id="more-3970"></span><br />其實小蛙根本不清楚為什麼原本可以執行後來不能執行，也是因為小蛙裝 Ubuntu 16.04 的時候，php5.x ~ php7.x 新舊交替，每次在想要裝 5.x 還是 7.x，看著趨勢會默默跑去裝 7.x，但有些程式直上 7.x 就是噴錯給你看，例如：<a href="https://noter.tw/3913/ubuntu-16-04-phpmyadmin-deprecation-notice-with-php-7/" data-wpel-link="internal">這篇文章</a>，這實在難啊！<br />這次這個例子呢，安裝之前小蛙並沒有注意到底是用哪一個，多 php 版本的情況下感覺好像有點自找麻煩，<del>不過感覺沒道理不過是 make swoole 就把 php cli 從 5.x 變成 7.x 版本(還是真的會這樣 &#8230;?) </del>詢問了朋友，應該是有可能在 make &amp;&amp; make install 的過程中被改掉，好吧！知道問題在哪就好處理了，如果 php cli 被改掉就 &#8230; 改回來唄！<br />調整 php 版本蠻簡單的，根據 參考資料1，小蛙這邊記錄兩種自己用的方法：</p>
<h2 class="para">手動設定 php 版本 &#8211; 1</h2>
<p>如果你很明確知道 php 的執行檔放在哪個地方，直接下指令就可以切換了</p>


<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">update-alternatives --set php /usr/bin/php5.6</pre>



<h2 class="para wp-block-heading">清單挑選 php 版本 &#8211; 2</h2>



<p>第二個方法是列出所有的 php 版本，讓你可以直接用挑選的方式設定</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">update-alternatives --config php</pre>



<h2 class="para wp-block-heading">參考資料</h2>



<ul class="my-li bg-darkblue wp-block-list"><li> <a rel="noreferrer noopener nofollow external" href="https://stackoverflow.com/questions/42619312/switch-php-versions-on-commandline-ubuntu-16-04" target="_blank" data-wpel-link="external" class="wpel-icon-right">Switch php versions on commandline ubuntu 16.04 @ Stack Overflow<span class="wpel-icon wpel-image wpel-icon-6"></span></a> </li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3970/%e8%aa%bf%e6%95%b4-php-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">調整 php 版本</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/3970/%e8%aa%bf%e6%95%b4-php-%e7%89%88%e6%9c%ac/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ubuntu 16.04 編譯並安裝 Swoole</title>
		<link>https://noter.tw/3963/ubuntu-16-04-%e7%b7%a8%e8%ad%af%e4%b8%a6%e5%ae%89%e8%a3%9d-swoole/</link>
					<comments>https://noter.tw/3963/ubuntu-16-04-%e7%b7%a8%e8%ad%af%e4%b8%a6%e5%ae%89%e8%a3%9d-swoole/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Thu, 14 Jun 2018 14:59:16 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpize]]></category>
		<category><![CDATA[swoole]]></category>
		<guid isPermaLink="false">https://wazai.net/?p=3963</guid>

					<description><![CDATA[<p>接到一個好朋友的求救，需要在 Ubuntu 16.04 下安裝 Swoole 模組，讓 apache 更虎虎生風！第一次做這件事，記錄留個底，也許能幫到需要的人。 介紹這有什麼功能以及強項一向不是小蛙&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3963/ubuntu-16-04-%e7%b7%a8%e8%ad%af%e4%b8%a6%e5%ae%89%e8%a3%9d-swoole/" data-wpel-link="internal">Ubuntu 16.04 編譯並安裝 Swoole</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>接到一個好朋友的求救，需要在 Ubuntu 16.04 下安裝 Swoole 模組，讓 apache 更虎虎生風！第一次做這件事，記錄留個底，也許能幫到需要的人。</p>



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



<p>介紹這有什麼功能以及強項一向不是小蛙的 style，這邊就是記錄怎麼把這東西安裝起來比較重要，介紹性的文章就找一些專業的介紹文來看吧！總之會來到這邊的人應該是想知道怎麼把這東西裝起來的吧！(應該吧！哈哈)</p>



<p>這個編譯過程比想像中的還要容易一些，期間沒有遇到什麼詭異的大問題，直接進入步驟吧！</p>



<h2 class="para wp-block-heading">步驟</h2>



<p>先到 <a rel="noreferrer noopener nofollow external" href="https://github.com/swoole/swoole-src/releases/tag/v2.0.10-stable" target="_blank" data-wpel-link="external" class="wpel-icon-right">參考資料1<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 下載 Source Code，小蛙下載的時候已經有 v4.0.0，但總覺得怪怪的，因此還是找了 <a rel="noreferrer noopener nofollow external" href="https://github.com/swoole/swoole-src/releases/tag/v2.0.10-stable" target="_blank" data-wpel-link="external" class="wpel-icon-right">v2.0.10-stable<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 來做比較保險，至少名稱上有個 stable，下載完後解壓縮，並進入該資料夾。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">wget https://github.com/swoole/swoole-src/archive/v2.0.10-stable.zip
unzip v2.0.10-stable.zip
cd swoole-src-2.0.10-stable/</pre>



<p>安裝 php-dev</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">apt-get install php-dev</pre>



<p>執行編譯，這邊小蛙的主機上竟然沒有 make，必須要先 <code>apt-get install make</code> 來安裝 make 工具。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">phpize
./configure
make</pre>



<p>完成囉！</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://noter.tw/wp-content/uploads/2018/06/swoole_make_install.png" alt="swoole make install Ubuntu 16.04 編譯並安裝 Swoole" title="Ubuntu 16.04 編譯並安裝 Swoole"></figure></div>



<p>修改 php.ini 導入模組，小蛙使用的這版 php 跟以前那種直接去 php.ini 新增 extension=swoole.so 不太一樣，而是在安裝目錄下載入 module。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">cd /etc/php/7.2/mods-available/
隨便複製一個 ini
cp mysqli.ini swoole.ini
vim swoole.ini
把 extension=mysqli.so 改成 extension=swoole.so
cd /etc/php/7.2/cli/conf.d/
ln -s /etc/php/7.2/mods-available/swoole.ini 20-swoole.ini
service apache2 restart
檢查是否正確安裝
php -m | grep 'swoole'</pre>



<p>目前小蛙也還在看看 swoole 能做到哪些酷炫的事情，看看是否自己的主機也要裝這個模組！</p>



<h2 class="para wp-block-heading">參考資料</h2>



<ul class="my-li bg-darkblue wp-block-list"><li><a rel="noreferrer noopener nofollow external" href="https://github.com/swoole/swoole-src/releases/tag/v2.0.10-stable" target="_blank" data-wpel-link="external" class="wpel-icon-right">Swoole @ GitHub<span class="wpel-icon wpel-image wpel-icon-6"></span></a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3963/ubuntu-16-04-%e7%b7%a8%e8%ad%af%e4%b8%a6%e5%ae%89%e8%a3%9d-swoole/" data-wpel-link="internal">Ubuntu 16.04 編譯並安裝 Swoole</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/3963/ubuntu-16-04-%e7%b7%a8%e8%ad%af%e4%b8%a6%e5%ae%89%e8%a3%9d-swoole/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
