<?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>Apache &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Tue, 24 Oct 2023 00:32:39 +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>Apache &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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>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[2019]]></category>
		<category><![CDATA[關閉 TLSv1]]></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>
		<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>
	</channel>
</rss>
