

<?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>DigitalOcean &#8211; Max的程式語言筆記</title>
	<atom:link href="https://stackoverflow.max-everyday.com/tag/digitalocean/feed/" rel="self" type="application/rss+xml" />
	<link>https://stackoverflow.max-everyday.com</link>
	<description>我要當一個豬頭，快樂過每一天</description>
	<lastBuildDate>Fri, 25 Aug 2023 07:52:40 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/max-stackoverflow-256.png</url>
	<title>DigitalOcean &#8211; Max的程式語言筆記</title>
	<link>https://stackoverflow.max-everyday.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>中國大陸的雲端主機供應商</title>
		<link>https://stackoverflow.max-everyday.com/2018/03/vps-cloud-in-china/</link>
					<comments>https://stackoverflow.max-everyday.com/2018/03/vps-cloud-in-china/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Sat, 31 Mar 2018 09:33:35 +0000</pubDate>
				<category><![CDATA[WordPress筆記]]></category>
		<category><![CDATA[電腦相關應用]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=2210</guid>

					<description><![CDATA[如果想成為一個前往中國大陸的「跨境電商」，如果需...]]></description>
										<content:encoded><![CDATA[<p>如果想成為一個前往中國大陸的「跨境電商」，如果需要在大陸架設 demo 環境，可以使用這些公司提供的服務。阿里雲租虛擬主機，一個月是 19美元（約台幣600), 阿里云主機在香港的金額是 9美元（約台幣 180元）。</p>
<p>10 Best Cloud, VPS and Shared Hosting Platform for China Market</p>
<ol>
<li>AWS<br />
<a href="https://www.amazonaws.cn/">https://www.amazonaws.cn/</a><br />
<img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-2212" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2018/03/Screenshot-2018-03-31-17.24.08.jpg" alt="" width="411" height="270" srcset="https://stackoverflow.max-everyday.com/wp-content/uploads/2018/03/Screenshot-2018-03-31-17.24.08.jpg 411w, https://stackoverflow.max-everyday.com/wp-content/uploads/2018/03/Screenshot-2018-03-31-17.24.08-380x250.jpg 380w" sizes="(max-width: 411px) 100vw, 411px" /></li>
<li>Sino<br />
<a href="http://www.sinohosting.net/">http://www.sinohosting.net/</a></li>
<li>Alibaba<br />
<a href="https://www.alibabacloud.com/zh/pricing">https://www.alibabacloud.com/zh/pricing</a><br />
<img decoding="async" class="alignnone wp-image-2208 size-thumbnail" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2018/03/Screenshot-2018-03-31-17.06.03-300x300.jpg" alt="" width="300" height="300" /></li>
<li>新一代数据中心<br />
<a href="https://www.gzidc.com/">https://www.gzidc.com/</a></li>
<li>西部数码<br />
<a href="https://www.west.cn/">https://www.west.cn/</a></li>
<li>HaBangNet<br />
<a href="http://www.habangnet.com/">http://www.habangnet.com/</a></li>
<li>金山云<br />
<a href="http://www.ksyun.com/">http://www.ksyun.com/</a></li>
<li>腾讯云 (Tencent Cloud)<br />
<a href="https://cloud.tencent.com/?lang=zh">https://cloud.tencent.com/?lang=zh</a></li>
<li>百度云<br />
<a href="https://cloud.baidu.com/">https://cloud.baidu.com/</a></li>
<li>全民云<br />
<a href="https://www.ucloud.cn/">https://www.ucloud.cn/</a></li>
</ol>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2018/03/vps-cloud-in-china/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>中國大陸的阿里雲租虛擬主機一個月是 19美元</title>
		<link>https://stackoverflow.max-everyday.com/2018/03/alibabacloud/</link>
					<comments>https://stackoverflow.max-everyday.com/2018/03/alibabacloud/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Sat, 31 Mar 2018 09:15:41 +0000</pubDate>
				<category><![CDATA[WordPress筆記]]></category>
		<category><![CDATA[電腦相關應用]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=2207</guid>

					<description><![CDATA[如果想成為一個前往中國大陸的「跨境電商」，如果需...]]></description>
										<content:encoded><![CDATA[<p>如果想成為一個前往中國大陸的「跨境電商」，如果需要在大陸架設 demo 環境，在阿里雲租虛擬主機，一個月是 19美元（約台幣600), 阿里云主機在香港的金額是 9美元（約台幣 180元），主機在 新加坡，悉尼，法兰克福，硅谷， 维吉尼亚。一個月是 4.5美元。</p>
<p>阿里云的 4.5美比 digitalocean 的 5.0 美元還便宜，阿里云給的 SSD 空間(25GB)比 digitalocean 還大.</p>
<p>阿里云定價：<br />
<a href="https://www.alibabacloud.com/zh/pricing">https://www.alibabacloud.com/zh/pricing</a></p>
<p><img decoding="async" class="alignnone size-full wp-image-2208" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2018/03/Screenshot-2018-03-31-17.06.03.jpg" alt="" width="846" height="576" srcset="https://stackoverflow.max-everyday.com/wp-content/uploads/2018/03/Screenshot-2018-03-31-17.06.03.jpg 846w, https://stackoverflow.max-everyday.com/wp-content/uploads/2018/03/Screenshot-2018-03-31-17.06.03-600x409.jpg 600w, https://stackoverflow.max-everyday.com/wp-content/uploads/2018/03/Screenshot-2018-03-31-17.06.03-768x523.jpg 768w" sizes="(max-width: 846px) 100vw, 846px" /></p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2018/03/alibabacloud/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Use SSH Keys connect to Linux server</title>
		<link>https://stackoverflow.max-everyday.com/2017/12/how-to-use-ssh-keys-to-linux-server/</link>
					<comments>https://stackoverflow.max-everyday.com/2017/12/how-to-use-ssh-keys-to-linux-server/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Thu, 07 Dec 2017 08:09:22 +0000</pubDate>
				<category><![CDATA[電腦相關應用]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[password]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=1686</guid>

					<description><![CDATA[如何透過 pub key 不用打密碼連進 lin...]]></description>
										<content:encoded><![CDATA[<p>如何透過 pub key 不用打密碼連進 linux server 裡，當然可以把密碼設的超級長，之後就透過 pub key 登入比較有效率。在 ssh client side 拿到的 key 在第1 次 ssh 時還是可以使用 id/password 方式去登入，再透過 vi ~/.ssh/authorized_keys 加入到 server side 即可。</p>
<p>&nbsp;</p>
<p><strong>Note</strong>: <em>This guide is for Mac OS X and Linux users. If you are using Windows on your home computer, follow <a href="https://www.digitalocean.com/community/articles/how-to-use-ssh-keys-with-putty-on-digitalocean-droplets-windows-users">this guide</a> instead.</em></p>
<hr />
<h4>Step One—Create the RSA Key Pair</h4>
<blockquote>
<pre>ssh-keygen -t rsa</pre>
</blockquote>
<hr />
<h4>Step Two—Store the Keys and Passphrase</h4>
<p>&nbsp;</p>
<p>Once you have entered the Gen Key command, you will get a few more questions:</p>
<pre>Enter file in which to save the key (/demo/.ssh/id_rsa):</pre>
<p>You can press enter here, saving the file to the user home (in this case, my example user is called demo).</p>
<pre>Enter passphrase (empty for no passphrase):</pre>
<p>It&#8217;s up to you whether you want to use a passphrase The entire key generation process looks like this:</p>
<pre>ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/demo/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /demo/.ssh/id_rsa.
Your public key has been saved in /demo/.ssh/id_rsa.pub.
The key fingerprint is:
4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:44:4d:93:67 demo@a
The key's randomart image is:
+--[ RSA 2048]----+
|          .oo.   |
|         .  o.E  |
|        + .  o   |
|     . = = .     |
|      = S = .    |
|     o + = +     |
|      . o + o .  |
|           . o   |
|                 |
+-----------------+</pre>
<p>The public key is now located in /demo/.ssh/id_rsa.pub The private key (identification) is now located in /demo/.ssh/id_rsa</p>
<hr />
<h4>Step Three—Copy the SSH Keys</h4>
<p>透過  cat ~/.ssh/id_rsa.pub 就可以拿到公開的 key</p>
<p>再把內容都加入(append)到要被 ssh 連進去的 server 的 ~/.ssh/authorized_keys 檔案裡，就可以讓其他台電腦不用打密碼連進 ssh server 了。</p>
<p>&nbsp;</p>
<h4>相關文章：</h4>
<p>保衛 OpenSSH</p>
<p>中文版：<a href="https://wiki.centos.org/zh-tw/HowTos/Network/SecuringSSH">https://wiki.centos.org/zh-tw/HowTos/Network/SecuringSSH</a></p>
<p>英文版：<a href="https://wiki.centos.org/HowTos/Network/SecuringSSH">https://wiki.centos.org/HowTos/Network/SecuringSSH</a></p>
<hr />
<p class="line874">OpenSSH（或者 Secure Shell）以經成為一個取代 telnet 協議作遠端存取用的現有標準。SSH 已經令 telnet 等協議多餘的，當中絕大部份原因是由於連線被加密，以及不再以純文字公開地傳送密碼。<span id="line-8" class="anchor"></span><span id="line-9" class="anchor"></span></p>
<p class="line874">然而，預設的 ssh 安裝並非完美。當你營運一個 ssh 伺服器時，有數個簡單的步驟可以明顯地加固你的安裝。<span id="line-10" class="anchor"></span><span id="line-11" class="anchor"></span></p>
<h2 id="head-198aee1737631c45022da8557a578b41290d3a24">1. 採用難猜測的密碼／用戶名稱</h2>
<p class="line874">如果你所營運的 ssh 是對外的，你首先會發現的事情，很可能就是駭客嘗試猜/測用戶名稱／密碼的記錄。駭客一般會掃描連接埠 22（ssh 預設聆聽的連接埠）來找尋執行 ssh 的機器，然後嘗試強行攻擊它。借著使用難猜測的密碼，我們希望任何攻擊在成功前會被記錄底及被留意到。<span id="line-13" class="anchor"></span><span id="line-14" class="anchor"></span></p>
<p class="line874">盼望你已經採用了難猜測的密碼。要不然，請嘗試選擁有以下特徵的密碼：<span id="line-15" class="anchor"></span><span id="line-16" class="anchor"></span></p>
<ul>
<li>最少有 8 個字元<span id="line-17" class="anchor"></span></li>
<li>同時有大寫和小寫字母<span id="line-18" class="anchor"></span></li>
<li>同時有字母和數目字<span id="line-19" class="anchor"></span></li>
<li>有非英數的字元（例如 ! &#8221; £ $ % ^ 等特別字元）<span id="line-20" class="anchor"></span></li>
</ul>
<p class="line874">使用難測密碼的好處並不止於 ssh，它更會影響到系統安全的各個範疇。有關密碼的更多資訊可以在 CentOS 的文檔內找到：<span id="line-21" class="anchor"></span><span id="line-22" class="anchor"></span></p>
<p class="line867"><a class="http" href="http://www.centos.org/docs/4/html/rhel-sg-en-4/s1-wstation-pass.html">http://www.centos.org/docs/4/html/rhel-sg-en-4/s1-wstation-pass.html</a><span id="line-23" class="anchor"></span><span id="line-24" class="anchor"></span></p>
<p class="line874">如果你完全沒法阻止你的用戶選用易猜測的密碼，請考慮以隨機產生或難猜測的字串作為用戶名稱。如果壞人不能猜測用戶名稱，他們便不能強加猜測密碼。然而，這只是隱晦資訊來換取安全，所以要留心用戶名稱透過用戶發送的電郵等途徑而被洩漏。<span id="line-25" class="anchor"></span><span id="line-26" class="anchor"></span></p>
<h2 id="head-875a293739a9d337484a2226bcbbbb4a8ee4c0b9">2. 停用 root 登入</h2>
<p class="line862">SSH 伺服器的設定都儲存在 <strong>/etc/ssh/sshd_confg</strong> 這個檔案。要停用 root 登入，請確定你有以下一行：<span id="line-28" class="anchor"></span></p>
<pre># 阻止 root 登入：
<span id="line-29" class="anchor"></span>PermitRootLogin no</pre>
<p class="line862">然後請重新啟動 sshd 服務：<span id="line-31" class="anchor"></span></p>
<pre>service sshd restart
<span id="line-32" class="anchor"></span></pre>
<p class="line862">你果你需要 root 的權限，請登入為一般用戶，然後使用 <strong>su</strong> 這個指令。<span id="line-34" class="anchor"></span><span id="line-35" class="anchor"></span></p>
<h2 id="head-5ced0101962be14377374e63070383323467929e">3. 限制用戶登入</h2>
<p class="line862">SSH 登入可以局限給某些需要遠端存取的用戶。如果你的系統有很多用戶，一個合理的做法就是局限遠端存取給那真正有需要的用戶，藉以減低其他用戶採用易測密碼的影響。在 <strong>/etc/ssh/sshd_config</strong> 內加入 AllowUsers 一行，以空格隔開用戶名稱。例如：<span id="line-37" class="anchor"></span></p>
<pre>AllowUsers alice bob</pre>
<p class="line874">接著請重新啟動 sshd 服務。<span id="line-39" class="anchor"></span><span id="line-40" class="anchor"></span></p>
<p>&nbsp;</p>
<h2 id="head-9998a215b709986d1be15eb92098ad3aa1f7ddb5">4. 停用第 1 類協議</h2>
<p class="line862">SSH 可以採用兩款協議：第 1 類及第 2 類協議。較舊的第 1 類協議的安全性較低，因此它應該被停用，除非你知道你必須要使用它。請在 <strong>/etc/ssh/sshd_config</strong> 檔內找尋以下一行，解除註釋，並作出如下修改：<span id="line-42" class="anchor"></span></p>
<pre># Protocol 2,1
<span id="line-43" class="anchor"></span>Protocol 2
<span id="line-44" class="anchor"></span></pre>
<p class="line874">然後請重新啟動 sshd 服務。<span id="line-46" class="anchor"></span><span id="line-47" class="anchor"></span></p>
<p>&nbsp;</p>
<h2 id="head-833ad44a400ce2cc2a11c4c1e20ec5ebf0a88e07">5. 採用非標準的連接埠</h2>
<p class="line862">根據預設值，ssh 在連接埠 22 聆聽進入的連線。一個駭客如果要斷定 ssh 是否在你的機器上運行，他最大可能就是掃描連接埠 22。一個有效混淆他的方法就是在非標準的連接埠上運行 ssh。任何未被使用的連接埠都可行，但首選的是 1024 以上的。很多人選用 2222 作為替代的連接埠（它很易記），正如 8080 經常被用作 HTTP 的替代連接埠。正正由於這個原因令它不是個好的選擇，因為任何掃描連接埠 22 的駭客亦不會放過連接埠 2222。隨機地選用一個未被使用的高位連接埠會比較合宜。要進行改動，請在你的 <strong>/etc/ssh/sshd_config</strong> 檔內加入以下一行：<span id="line-49" class="anchor"></span></p>
<pre># 在非標準的連接埠上執行 ssh：
<span id="line-50" class="anchor"></span>Port 2345  #修改我</pre>
<p class="line862">然後重新啟動 sshd 服務。請勿忘記在你的路由器及相關的防火牆規則裡作出任何必要的改動。譬如在 CentOS 7 你需要更改 firewalld：<span id="line-52" class="anchor"></span></p>
<pre>$ firewall-cmd --add-port 2345/tcp
<span id="line-53" class="anchor"></span>$ firewall-cmd --add-port 2345/tcp --permanent</pre>
<p class="line874">又或者在 CentOS 6：<span id="line-56" class="anchor"></span><span id="line-57" class="anchor"></span></p>
<pre>$ iptables -I INPUT -p tcp --dport 2345 -j ACCEPT</pre>
<p class="line862">在 CentOS 6 及以上版本，你亦需要更新 selinux，並正確地標籤所選用的連接埠，否則 sshd 便無法存取它。舉個例說：<span id="line-60" class="anchor"></span></p>
<pre>$ semanage port -a -t ssh_port_t -p tcp 2345 #請更改這處</pre>
<p class="line862">因為 ssh 不再在標準的連接埠上聆聽連線，你須要告訴客戶端要連線到哪個連接埠。在指令行上執行 ssh 客戶端時，你可以用 -p 選項來指定連接埠：<span id="line-63" class="anchor"></span></p>
<pre>$ ssh -p 2345 myserver</pre>
<p class="line862">又或者如果你使用 konqueror 的 fish 協議，你可用：<span id="line-65" class="anchor"></span></p>
<pre>fish://myserver:2345/remote/dir</pre>
<p class="line862">如果你覺得每次連線時都要指定連接埠似乎很痛苦，你只需在你個人的 <strong>~/.ssh/config</strong> 檔案裡加入一個指定連接埠的記錄：<span id="line-67" class="anchor"></span></p>
<pre> # 客戶端 ~/.ssh/config
<span id="line-68" class="anchor"></span>Host myserver
<span id="line-69" class="anchor"></span>HostName 72.232.194.162
<span id="line-70" class="anchor"></span>        User bob
<span id="line-71" class="anchor"></span>        Port 2345
<span id="line-72" class="anchor"></span></pre>
<p class="line867"><strong>~/.ssh/config</strong> 必須有以下存取權：<span id="line-74" class="anchor"></span></p>
<pre>$ chmod 600 ~/.ssh/config
<span id="line-75" class="anchor"></span></pre>
<h2 id="head-7754a22695febc79d8fdb94319e8811605828200">6. 在防火牆過濾 SSH</h2>
<p>linux 裡有很多防火牆可以用，像是 iptables , ufw 或 firewall-cmd. 直接使用：</p>
<blockquote>
<pre>sudo ufw allow 22</pre>
</blockquote>
<p>上面的指令可以直接開啟某一個 port number.</p>
<p class="line862">如果你只須由一個 IP 位址進行遠端存取（例如由辦工室進入家中的伺服器），請考慮在你的路由器或 iptables 內加入一條防火牆的規則，將連接埠 22 的存取權限制到特定的 IP 位址，藉此對連線進行過濾。舉個例說，在 iptables 內你可以用這類型的規則達至這個目的：<span id="line-79" class="anchor"></span></p>
<pre>iptables -A INPUT -p tcp -s 72.232.194.162 --dport 22 -j ACCEPT</pre>
<p class="line874">SSH 亦對 TCP 包裝函式有內置支援，因此 ssh 服務的存取權亦可同時用 host.allow 及 hosts.deny 來進行管制。<span id="line-81" class="anchor"></span><span id="line-82" class="anchor"></span></p>
<p class="line862">如果你無法限制來源地的 IP 位址，而必須公開 ssh 連接埠，那麼 iptables 依然可以透過記錄及攔截來自同一 IP 位址的重覆登入嘗試，幫助你阻止強行的攻擊。例如：<span id="line-83" class="anchor"></span></p>
<pre>iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name ssh --rsource
<span id="line-84" class="anchor"></span>iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent ! --rcheck --seconds 60 --hitcount 4 --name ssh --rsource -j ACCEPT
<span id="line-85" class="anchor"></span></pre>
<p class="line862">第一條規則利用 <tt class="backtick">recent</tt> 模塊來記錄每個存取連接埠 22 的新嘗試。第二條規則檢查這個 IP 位址在過去 60 秒內有否嘗試 4 次或以上的連線，若然沒有更接納封包。注意這個規則須要輸入鏈採用 DROP 的預設政策。<span id="line-87" class="anchor"></span><span id="line-88" class="anchor"></span></p>
<p class="line874">如果你在非標準的連接埠上執行 ssh，請不要忘記對連接埠作出相應修改。情況許可的話，利用防火牆進行過濾是一個非常有效的方法來保衛 ssh 伺服器。<span id="line-89" class="anchor"></span><span id="line-90" class="anchor"></span></p>
<p class="line874">採用 FirewallD 服務的系統，可執行下列 firewall-cmd：<span id="line-91" class="anchor"></span><span id="line-92" class="anchor"></span></p>
<pre>firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT_direct 0 -p tcp --dport 22 -m state --state NEW -m recent --set
<span id="line-93" class="anchor"></span>firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT_direct 1 -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 30 --hitcount 4 -j REJECT --reject-with tcp-reset
<span id="line-94" class="anchor"></span>firewall-cmd --reload</pre>
<h2 id="head-3fbabbfd4efed14d16340fc3dddfb78e23be2b6c">7. 採用公鑰／私鑰來驗證</h2>
<p class="line874">採用加密金鑰來驗證提供兩大好處。首先，如果你應用公鑰／私鑰，是方便，因為你不用再輸入密碼（除非你用密碼來保護你的金鑰）。第二，當伺服器能進行金鑰對的驗證，你便可以完全停用密碼驗證，意即存取時靠賴授權的金鑰 —— 因此不再有猜測密碼的嘗試。<span id="line-98" class="anchor"></span><span id="line-99" class="anchor"></span></p>
<p class="line874">建立及在你的 ssh 伺服器上安裝金鑰對是個相對地簡單的過程。<span id="line-100" class="anchor"></span><span id="line-101" class="anchor"></span></p>
<p class="line862">首先，在你會用來連線到伺服器的客戶端上建立一對金鑰（你須要在每台用來連線的機器上這樣做）：<span id="line-102" class="anchor"></span></p>
<pre>$ ssh-keygen -t rsa</pre>
<p class="line862">這樣做會在你的（隱藏了的）<strong>~/.ssh</strong> 目錄內建立兩個檔案，名叫：<strong>id_rsa</strong> 及 <strong>id_rsa.pub</strong>。第一個檔案：<strong>id_rsa</strong> 是你的私鑰，而另一個：<strong>id_rsa.pub</strong> 是你的公鑰。<span id="line-104" class="anchor"></span><span id="line-105" class="anchor"></span></p>
<p class="line862">如果你不想每次連線時都被問及密碼（它是用來解開特定的公鑰），在建立金鑰對的時候，你只須按 <strong>enter</strong> 作為密碼。建立金鑰對時，是否以密碼加密純粹是你的決定。如何你不將金鑰加密，任何人奪得你的本地機器後，便自動擁有遠端伺服器的 ssh 存取權。此外，本地機器上的 root 能夠存取你的金鑰：但假若你不能信任 root（或者 root 已被攻佔），你已經大禍臨頭。將金鑰加密捨棄了不用密碼的 ssh 伺服器，來換取額外的安全，得來的就是輸入密碼來使用這條金鑰。你可利用 <strong>ssh_agent</strong> 這個程式進一步簡化這個程序。<span id="line-106" class="anchor"></span><span id="line-107" class="anchor"></span></p>
<p class="line862">現在為你的私鑰設定權限：<span id="line-108" class="anchor"></span></p>
<pre>$ chmod 700 ~/.ssh
<span id="line-109" class="anchor"></span>$ chmod 600 ~/.ssh/id_rsa</pre>
<p class="line862">請將公鑰（id_rsa.pub）複製到伺服器上，然後安裝它在 authorized_keys 清單內：<span id="line-111" class="anchor"></span></p>
<pre>$ cat id_rsa.pub &gt;&gt; ~/.ssh/authorized_keys</pre>
<p class="line867"><strong>註：</strong>一旦你匯入了公鑰，你可以在伺服器上刪除它。<span id="line-113" class="anchor"></span><span id="line-114" class="anchor"></span></p>
<p class="line862">最後，設定伺服器上的檔案權限：<span id="line-115" class="anchor"></span></p>
<pre>$ chmod 700 ~/.ssh
<span id="line-116" class="anchor"></span>$ chmod 600 ~/.ssh/authorized_keys</pre>
<p class="line862">如果 <strong>/etc/ssh/sshd_config</strong> 內的 <tt class="backtick">StrictModes</tt> 被啟用（預設值），以上的權限是<strong>必須的</strong>。<span id="line-118" class="anchor"></span><span id="line-119" class="anchor"></span></p>
<p class="line862">請確保你已設置正確的 SELinux 脈絡：<span id="line-120" class="anchor"></span></p>
<pre>$ restorecon -Rv ~/.ssh</pre>
<p class="line874">現在當你登入伺服器的時候，你便不用再輸入密碼（除非你在建立金鑰對的時候輸入了一個密碼）。ssh 預設是會先利用金鑰進行驗證。如何它找不到金鑰，或驗證失敗，ssh 會回落到平常的密碼驗證。<span id="line-123" class="anchor"></span><span id="line-124" class="anchor"></span></p>
<p class="line862">一旦你檢查過可以用金鑰對來登入伺服器，你可以在你的 <strong>/etc/ssh/sshd_conf</strong> 檔內加入以下設定來停用密碼驗證：<span id="line-125" class="anchor"></span></p>
<pre># 停用密碼驗證，強制使用金鑰
<span id="line-126" class="anchor"></span>PasswordAuthentication no</pre>
<h2 id="head-37c37c55c8be39700143ef4559d2542a47119e22">8. 常見問題（FAQ）</h2>
<p class="line874">問：CentOS 採用 X 版的 OpenSSH，而最新版本是 Y 版。X 版藏有一個嚴重的安全性漏洞，我應否升級？<span id="line-129" class="anchor"></span><span id="line-130" class="anchor"></span></p>
<p class="line874">答：不應該。上游供應者有一個政策，會將最新版本的安全性修正反向移植到現有的發行版本內。只要你擁有最新的更新，你的 CentOS 發行版本已經得到全面修正。有關反向移植安全性修正的詳情，請參閱這裡：<span id="line-131" class="anchor"></span><span id="line-132" class="anchor"></span></p>
<p class="line867"><a class="http" href="http://www.redhat.com/advice/speaks_backport.html">http://www.redhat.com/advice/speaks_backport.html</a><span id="line-133" class="anchor"></span><span id="line-134" class="anchor"></span></p>
<p class="line874">問：我如何令 ssh 容讓以 NFS 共享用戶主目錄的機器採用無密碼的驗證？<span id="line-135" class="anchor"></span><span id="line-136" class="anchor"></span></p>
<p class="line874">答：SELinux 預設攔阻 root 存取以 NFS 共享、非公用的目錄及檔案，因此 ssh 無法讀取 ~/.ssh 內的用戶金鑰檔。若要批準存取權，請用以下指令更改 use_nfs_home_dirs 的設定值：<span id="line-137" class="anchor"></span><span id="line-138" class="anchor"></span></p>
<pre>setsebool -P use_nfs_home_dirs 1</pre>
<p class="line867"><a class="https" href="https://www.centos.org/forums/viewtopic.php?t=49194">https://www.centos.org/forums/viewtopic.php?t=49194</a><span id="line-141" class="anchor"></span><span id="line-142" class="anchor"></span></p>
<h2 id="head-e5b42453a3ff59155760b22629133fa5f8459d4d">9. 連結</h2>
<p class="line867"><a class="http" href="http://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-openssh.html">http://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-openssh.html</a><span id="line-144" class="anchor"></span><span id="line-145" class="anchor"></span></p>
<p class="line867"><a class="http" href="http://www.dragonresearchgroup.org/insight/sshpwauth-tac.html">http://www.dragonresearchgroup.org/insight/sshpwauth-tac.html</a></p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2017/12/how-to-use-ssh-keys-to-linux-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>python mysql Error: (1366, &#8220;Incorrect string value:</title>
		<link>https://stackoverflow.max-everyday.com/2017/03/python-mysql-error-1366-incorrect-string-value/</link>
					<comments>https://stackoverflow.max-everyday.com/2017/03/python-mysql-error-1366-incorrect-string-value/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Tue, 21 Mar 2017 19:51:10 +0000</pubDate>
				<category><![CDATA[電腦相關應用]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=384</guid>

					<description><![CDATA[又遇到新的問題，在  Connection 增加...]]></description>
										<content:encoded><![CDATA[<p>又遇到新的問題，在  Connection 增加了 charset=&#8221;utf8&#8243; 之後，原本的錯誤訊息從</p>
<pre>mysql Error: 'latin-1' codec can't encode character u</pre>
<p>變成：</p>
<pre>Error: (1366, "Incorrect string value:</pre>
<p>&nbsp;</p>
<p>先下指令看看 database schema:</p>
<pre>SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';</pre>
<p>或指令：</p>
<pre>show variables like 'char%';</pre>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-385" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/03/Screenshot-2017-03-22-03.24.47.jpg" alt="" width="1458" height="600" /></p>
<p>&nbsp;</p>
<p>原來 database 被設成 latin1, 所以會出錯，要解法如下：</p>
<hr />
<p>Use the <a href="http://dev.mysql.com/doc/refman/5.1/en/alter-database.html"><code>ALTER DATABASE</code></a> and <a href="http://dev.mysql.com/doc/refman/5.1/en/alter-table.html"><code>ALTER TABLE</code></a> commands.</p>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="kwd">ALTER</span> <span class="kwd">DATABASE</span><span class="pln"> databasename CHARACTER </span><span class="kwd">SET</span><span class="pln"> utf8mb4 </span><span class="kwd">COLLATE</span><span class="pln"> utf8mb4_unicode_ci</span><span class="pun">;</span>
<span class="kwd">ALTER</span> <span class="kwd">TABLE</span><span class="pln"> tablename </span><span class="kwd">CONVERT</span> <span class="kwd">TO</span><span class="pln"> CHARACTER </span><span class="kwd">SET</span><span class="pln"> utf8mb4 </span><span class="kwd">COLLATE</span><span class="pln"> utf8mb4_unicode_ci</span><span class="pun">;</span></code></pre>
<p>Or if you&#8217;re still on MySQL 5.5.2 or older which didn&#8217;t support 4-byte UTF-8, use <code>utf8</code> instead of <code>utf8mb4</code>:</p>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="kwd">ALTER</span> <span class="kwd">DATABASE</span><span class="pln"> databasename CHARACTER </span><span class="kwd">SET</span><span class="pln"> utf8 </span><span class="kwd">COLLATE</span><span class="pln"> utf8_unicode_ci</span><span class="pun">;</span>
<span class="kwd">ALTER</span> <span class="kwd">TABLE</span><span class="pln"> tablename </span><span class="kwd">CONVERT</span> <span class="kwd">TO</span><span class="pln"> CHARACTER </span><span class="kwd">SET</span><span class="pln"> utf8 </span><span class="kwd">COLLATE</span><span class="pln"> utf8_unicode_ci</span><span class="pun">;</span></code></pre>
<hr />
<p>原來，先下這2個指令，才能修改 connection charset, 之後建立的  database &amp; table, charset 才會是對的。</p>
<p>mysql&gt;</p>
<pre>SET NAMES 'utf8';
SET CHARACTER SET utf8;</pre>
<hr />
<p>I would not suggest Richies answer, because you are screwing up the data inside the database. You would not fix your problem but try to &#8220;hide&#8221; it and not being able to perform essential database operations with the crapped data.</p>
<p>If you encounter this error either the data you are sending is not UTF-8 encoded, or your connection is not UTF-8. First, verify, that the data source (a file, &#8230;) <em>really</em> is UTF-8.</p>
<p>Then, check your database connection, you should do this after connecting:</p>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="kwd">SET</span><span class="pln"> NAMES </span><span class="str">'utf8'</span><span class="pun">;</span>
<span class="kwd">SET</span><span class="pln"> CHARACTER </span><span class="kwd">SET</span><span class="pln"> utf8</span><span class="pun">;</span></code></pre>
<p>Next, verify that the tables where the data is stored have the utf8 character set:</p>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="kwd">SELECT</span>
  <span class="pun">`</span><span class="pln">tables</span><span class="pun">`.`</span><span class="pln">TABLE_NAME</span><span class="pun">`,</span>
  <span class="pun">`</span><span class="pln">collations</span><span class="pun">`.`</span><span class="pln">character_set_name</span><span class="pun">`</span>
<span class="kwd">FROM</span>
  <span class="pun">`</span><span class="pln">information_schema</span><span class="pun">`.`</span><span class="pln">TABLES</span><span class="pun">`</span> <span class="kwd">AS</span> <span class="pun">`</span><span class="pln">tables</span><span class="pun">`,</span>
  <span class="pun">`</span><span class="pln">information_schema</span><span class="pun">`.`</span><span class="pln">COLLATION_CHARACTER_SET_APPLICABILITY</span><span class="pun">`</span> <span class="kwd">AS</span> <span class="pun">`</span><span class="pln">collations</span><span class="pun">`</span>
<span class="kwd">WHERE</span>
  <span class="pun">`</span><span class="pln">tables</span><span class="pun">`.`</span><span class="pln">table_schema</span><span class="pun">`</span> <span class="pun">=</span> <span class="kwd">DATABASE</span><span class="pun">()</span>
  <span class="kwd">AND</span> <span class="pun">`</span><span class="pln">collations</span><span class="pun">`.`</span><span class="pln">collation_name</span><span class="pun">`</span> <span class="pun">=</span> <span class="pun">`</span><span class="pln">tables</span><span class="pun">`.`</span><span class="pln">table_collation</span><span class="pun">`</span>
<span class="pun">;

</span></code></pre>
<p>Last, check your database settings:</p>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="pln">mysql</span><span class="pun">&gt;</span><span class="pln"> show variables </span><span class="kwd">like</span> <span class="str">'%colla%'</span><span class="pun">;</span><span class="pln">
mysql</span><span class="pun">&gt;</span><span class="pln"> show variables </span><span class="kwd">like</span> <span class="str">'%charac%'</span><span class="pun">;</span></code></pre>
<p>If source, transport and destination are UTF-8, your problem is gone;)</p>
<hr />
<p>change database collation:</p>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="kwd">ALTER</span> <span class="kwd">DATABASE</span> <span class="pun">&lt;</span><span class="pln">database_name</span><span class="pun">&gt;</span><span class="pln"> CHARACTER </span><span class="kwd">SET</span><span class="pln"> utf8 </span><span class="kwd">COLLATE</span><span class="pln"> utf8_unicode_ci</span><span class="pun">;</span></code></pre>
<p>change table collation:</p>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="kwd">ALTER</span> <span class="kwd">TABLE</span> <span class="pun">&lt;</span><span class="pln">table_name</span><span class="pun">&gt;</span> <span class="kwd">CONVERT</span> <span class="kwd">TO</span><span class="pln"> CHARACTER </span><span class="kwd">SET</span><span class="pln"> utf8 </span><span class="kwd">COLLATE</span><span class="pln"> utf8_unicode_ci</span><span class="pun">;</span></code></pre>
<p>change column collation:</p>
<pre class="lang-sql prettyprint prettyprinted"><code><span class="kwd">ALTER</span> <span class="kwd">TABLE</span> <span class="pun">&lt;</span><span class="pln">table_name</span><span class="pun">&gt;</span><span class="pln"> MODIFY </span><span class="pun">&lt;</span><span class="pln">column_name</span><span class="pun">&gt;</span><span class="pln"> VARCHAR</span><span class="pun">(</span><span class="lit">255</span><span class="pun">)</span><span class="pln"> CHARACTER </span><span class="kwd">SET</span><span class="pln"> utf8 </span><span class="kwd">COLLATE</span><span class="pln"> utf8_unicode_ci</span><span class="pun">;</span></code></pre>
<p>More info:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/1036454/what-are-the-diffrences-between-utf8-general-ci-and-utf8-unicode-ci">What are the diffrences between utf8_general_ci and utf8_unicode_ci?</a></li>
<li><a href="http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci">What&#8217;s the difference between utf8_general_ci and utf8_unicode_ci</a></li>
<li><a href="http://stackoverflow.com/questions/1294117/how-to-change-collation-of-database-table-column">How to change collation of database, table, column?</a></li>
</ul>
<hr />
<p>自動修改所有table的 python script:</p>
<p>If you have this problem here&#8217;s a python script to change all the columns of your mysql database automatically.</p>
<pre class="default prettyprint prettyprinted"><code><span class="com">#! /usr/bin/env python</span>
<span class="kwd">import</span> <span class="typ">MySQLdb</span><span class="pln">

host </span><span class="pun">=</span> <span class="str">"localhost"</span><span class="pln">
passwd </span><span class="pun">=</span> <span class="str">"passwd"</span><span class="pln">
user </span><span class="pun">=</span> <span class="str">"youruser"</span><span class="pln">
dbname </span><span class="pun">=</span> <span class="str">"yourdbname"</span><span class="pln">

db </span><span class="pun">=</span> <span class="typ">MySQLdb</span><span class="pun">.</span><span class="pln">connect</span><span class="pun">(</span><span class="pln">host</span><span class="pun">=</span><span class="pln">host</span><span class="pun">,</span><span class="pln"> user</span><span class="pun">=</span><span class="pln">user</span><span class="pun">,</span><span class="pln"> passwd</span><span class="pun">=</span><span class="pln">passwd</span><span class="pun">,</span><span class="pln"> db</span><span class="pun">=</span><span class="pln">dbname</span><span class="pun">)</span><span class="pln">
cursor </span><span class="pun">=</span><span class="pln"> db</span><span class="pun">.</span><span class="pln">cursor</span><span class="pun">()</span><span class="pln">

cursor</span><span class="pun">.</span><span class="pln">execute</span><span class="pun">(</span><span class="str">"ALTER DATABASE `%s` CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'"</span> <span class="pun">%</span><span class="pln"> dbname</span><span class="pun">)</span><span class="pln">

sql </span><span class="pun">=</span> <span class="str">"SELECT DISTINCT(table_name) FROM information_schema.columns WHERE table_schema = '%s'"</span> <span class="pun">%</span><span class="pln"> dbname
cursor</span><span class="pun">.</span><span class="pln">execute</span><span class="pun">(</span><span class="pln">sql</span><span class="pun">)</span><span class="pln">

results </span><span class="pun">=</span><span class="pln"> cursor</span><span class="pun">.</span><span class="pln">fetchall</span><span class="pun">()</span>
<span class="kwd">for</span><span class="pln"> row </span><span class="kwd">in</span><span class="pln"> results</span><span class="pun">:</span><span class="pln">
  sql </span><span class="pun">=</span> <span class="str">"ALTER TABLE `%s` convert to character set DEFAULT COLLATE DEFAULT"</span> <span class="pun">%</span> <span class="pun">(</span><span class="pln">row</span><span class="pun">[</span><span class="lit">0</span><span class="pun">])</span><span class="pln">
  cursor</span><span class="pun">.</span><span class="pln">execute</span><span class="pun">(</span><span class="pln">sql</span><span class="pun">)</span><span class="pln">
db</span><span class="pun">.</span><span class="pln">close</span><span class="pun">()</span></code></pre>
<p>&nbsp;</p>
<h4>相關文章：</h4>
<p>How to fix “Incorrect string value” errors?<br />
<a href="http://stackoverflow.com/questions/1168036/how-to-fix-incorrect-string-value-errors">http://stackoverflow.com/questions/1168036/how-to-fix-incorrect-string-value-errors</a></p>
<p>How to change the default collation of a database?<br />
<a href="http://stackoverflow.com/questions/5906585/how-to-change-the-default-collation-of-a-database">http://stackoverflow.com/questions/5906585/how-to-change-the-default-collation-of-a-database</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2017/03/python-mysql-error-1366-incorrect-string-value/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>err &#8216;ascii&#8217; codec can&#8217;t encode character u&#8217;\u7684&#8242; in position 7: ordinal not in range(128)</title>
		<link>https://stackoverflow.max-everyday.com/2017/03/err-ascii-codec-cant-encode-character-uu7684-in-position-7-ordinal-not-in-range128/</link>
					<comments>https://stackoverflow.max-everyday.com/2017/03/err-ascii-codec-cant-encode-character-uu7684-in-position-7-ordinal-not-in-range128/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Tue, 21 Mar 2017 18:05:13 +0000</pubDate>
				<category><![CDATA[Python筆記]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[macOS]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=377</guid>

					<description><![CDATA[又遇到 python 2.x 的編碼問題，一樣的...]]></description>
										<content:encoded><![CDATA[<p>又遇到 python 2.x 的編碼問題，一樣的程式碼在 Mac OS 上可以執行沒問題，放到 Linux上就出錯。但我又不想使 Dirty Hack 的方式去 reload sys.</p>
<p>下面這段 code：</p>
<pre>import sys; 
print(sys.getdefaultencoding())
print(sys.stdout.encoding)</pre>
<p>在 Mac OS 上執行結果：</p>
<blockquote><p>ascii<br />
UTF-8</p></blockquote>
<p>在 Linux 上執行結果：</p>
<blockquote><p>ascii<br />
ANSI_X3.4-1968</p></blockquote>
<p>在 Linux 上執行截圖：</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-378" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/03/Screenshot-2017-03-22-01.48.57.png" alt="" width="1294" height="146" /></p>
<p>&nbsp;</p>
<p>我的完整  source code:</p>
<pre>#!/usr/bin/env python
#encoding=utf-8

import sys; 
print(sys.getdefaultencoding())
print(sys.stdout.encoding)

import json

data='{"title": "Max Yao\u7684Dropboxlike"}'
json_obj = None
try :
    json_obj = json.loads(data)
    print json_obj['title']
except Exception as err:
    print "err", err
    json_obj = None
</pre>
<hr />
<p>應急解法：</p>
<p>in the &#8220;/etc/environment&#8221; file，add line:</p>
<pre>PYTHONIOENCODING=utf8</pre>
<p>但這段加了，其實沒什麼作用，主要的解法，還是在字串都要記得加  <span style="color: #ff0000;"><strong>u</strong></span>&#8220;xxxx&#8221;, 全部改用 unicode, 避免混合使用 str 和  unicode.</p>
<hr />
<p>下一個 Error:</p>
<p>mysql Error: &#8216;latin-1&#8217; codec can&#8217;t encode character u</p>
<hr />
<p>解法：<br />
<a href="http://stackoverflow.com/questions/3942888/unicodeencodeerror-latin-1-codec-cant-encode-character">http://stackoverflow.com/questions/3942888/unicodeencodeerror-latin-1-codec-cant-encode-character</a></p>
<p>I ran into this same issue when using the Python MySQLdb module. Since MySQL will let you store just about any binary data you want in a text field regardless of character set, I found my solution here:</p>
<p>Using UTF8 with Python MySQLdb</p>
<p>Edit: Quote from the above URL to satisfy the request in the first comment&#8230;</p>
<p>&#8220;UnicodeEncodeError:&#8217;latin-1&#8242; codec can&#8217;t encode character &#8230;&#8221;</p>
<p>This is because MySQLdb normally tries to encode everythin to latin-1. This can be fixed by executing the following commands right after you&#8217;ve etablished the connection:<br />
db.set_character_set(&#8216;utf8&#8217;)<br />
dbc.execute(&#8216;SET NAMES utf8;&#8217;)<br />
dbc.execute(&#8216;SET CHARACTER SET utf8;&#8217;)<br />
dbc.execute(&#8216;SET character_set_connection=utf8;&#8217;)<br />
&#8220;db&#8221; is the result of MySQLdb.connect(), and &#8220;dbc&#8221; is the result of db.cursor().</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h4>相關文章：</h4>
<p>Why should we NOT use sys.setdefaultencoding(“utf-8”) in a py script?<br />
<a href="http://stackoverflow.com/questions/3828723/why-should-we-not-use-sys-setdefaultencodingutf-8-in-a-py-script">http://stackoverflow.com/questions/3828723/why-should-we-not-use-sys-setdefaultencodingutf-8-in-a-py-script</a></p>
<p>有關 Python 2 和 Sublime Text 中文 Unicode 編碼問題的分析與理解<br />
<a href="https://read01.com/jjkMx.html">https://read01.com/jjkMx.html</a></p>
<p>有关 Python 2 和 Sublime Text 中文 Unicode 编码问题的分析与理解<br />
<a href="http://blog.csdn.net/saghir/article/details/50396660">http://blog.csdn.net/saghir/article/details/50396660</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2017/03/err-ascii-codec-cant-encode-character-uu7684-in-position-7-ordinal-not-in-range128/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>nginx 無法 proxy_pass header 301 302</title>
		<link>https://stackoverflow.max-everyday.com/2017/03/nginx-proxy_pass-301-302/</link>
					<comments>https://stackoverflow.max-everyday.com/2017/03/nginx-proxy_pass-301-302/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Fri, 03 Mar 2017 02:50:05 +0000</pubDate>
				<category><![CDATA[Dropboxlike開發筆記]]></category>
		<category><![CDATA[電腦相關應用]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<category><![CDATA[Dropboxlike]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=310</guid>

					<description><![CDATA[官方說明文件： https://www.ngin...]]></description>
										<content:encoded><![CDATA[<p>官方說明文件：<br />
<a href="https://www.nginx.com/blog/creating-nginx-rewrite-rules/">https://www.nginx.com/blog/creating-nginx-rewrite-rules/</a></p>
<p>&nbsp;</p>
<p>解法：</p>
<p>This is not ideal and it would be far better to have a clean workflow instead of doing this. But for curiosity, this could be informative to people that would wonder if it&#8217;s possible.</p>
<p><strong>Yes it is</strong>, using a combination of <code>error_page</code>, <code>rewrite</code>, <code>map</code>, <code>proxy_intercept_errors</code> and <code>proxy_redirect</code> directives and <code>$upstream_http</code> var pattern.</p>
<p>Keep in mind that it&#8217;s going far off the path nginx is designed to be driven on.</p>
<pre><code>map $upstream_http_location $redirect_uri {
    "~http://[^/]+/(?&lt;location_uri&gt;.*)$" "$location_uri";
}

upstream origin {
    server origin1.com;
}

server {

    listen 80;
    server_name nginx-front.com;

    proxy_set_header Host "origin1.com";
    proxy_redirect http://origin1.com/ /;

    location ~ ^/hls/(\w+)\.mp4\.m3u8$ {
        proxy_pass http://origin/m3ugen/segsrc/$1.mp4;
        proxy_intercept_errors on;
        error_page 301 302 = @handler;    
    }

    location @handler {
        rewrite ^ /$redirect_uri break;
        proxy_pass http://origin;
    }

}</code></pre>
<hr />
<div class="post-text">
<p>It is possible for <code>nginx</code> to intercept the 302 response code and process internally. I set up a test scenario which worked using this:</p>
<pre><code>location /some/uri/ {
    error_page 302 = @fallback;
    proxy_intercept_errors on;
    proxy_pass ...;
}
location @fallback {
    rewrite ^ /some/other/uri last;
}
</code></pre>
<p>This would of course be a blanket intercept without regard for the value of the response headers, but that may be adequate for your requirement. See <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page" rel="nofollow noreferrer">this</a> and <a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors" rel="nofollow noreferrer">this</a> for more.</p>
<hr />
</div>
<p>I succeeded in solving a more generic case when a redirect location can be any external URL.</p>
<pre><code>server {
    ...

    location / {
        proxy_pass http://backend;
        # You may need to uncomment the following line if your redirects are relative, e.g. /foo/bar
        #proxy_redirect / /;
        proxy_intercept_errors on;
        error_page 301 302 307 = @handle_redirects;
    }

    location @handle_redirects {
        set $saved_redirect_location '$upstream_http_location';
        proxy_pass $saved_redirect_location;
    }
}
</code></pre>
<p>Alternative approach, which is closer to what you describe, is covered in ServerFault answer to this question: <a href="http://serverfault.com/questions/641070/nginx-302-redirect-resolve-internally">http://serverfault.com/questions/641070/nginx-302-redirect-resolve-internally</a></p>
<p>&nbsp;</p>
<p>修改 sample:<br />
<a href="https://gist.github.com/sirsquidness/710bc76d7bbc734c7a3ff69c6b8ff591">https://gist.github.com/sirsquidness/710bc76d7bbc734c7a3ff69c6b8ff591</a></p>
<p>&nbsp;</p>
<p>資料來源：<br />
<a href="http://serverfault.com/questions/641070/nginx-302-redirect-resolve-internally">http://serverfault.com/questions/641070/nginx-302-redirect-resolve-internally</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2017/03/nginx-proxy_pass-301-302/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Easily Create a Multilingual WordPress Site</title>
		<link>https://stackoverflow.max-everyday.com/2017/02/how-to-easily-create-a-multilingual-wordpress-site/</link>
					<comments>https://stackoverflow.max-everyday.com/2017/02/how-to-easily-create-a-multilingual-wordpress-site/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Mon, 20 Feb 2017 09:10:30 +0000</pubDate>
				<category><![CDATA[WordPress筆記]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=203</guid>

					<description><![CDATA[透過 wordpress 寫多國語言的網站還滿簡...]]></description>
										<content:encoded><![CDATA[<p>透過 wordpress 寫多國語言的網站還滿簡單的耶。</p>
<p>首先要在 wordpress 裡安裝 Polylang 外掛(Plugins)：<br />
<a href="https://wordpress.org/plugins/polylang/">https://wordpress.org/plugins/polylang/</a></p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-206 size-full" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/Screenshot-2017-02-20-16.27.18.jpg" width="1520" height="1156" /></p>
<p>&nbsp;</p>
<p>裝好外掛後，要先新增語言(Langages)。</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-207 size-full" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/Screenshot-2017-02-20-16.29.23.jpg" width="1136" height="1306" /></p>
<p>由於 zh_TW, zh_CN 預設用的代碼都是 zh, 不能2個都用zh, 所以我改用 tw 和 cn, 理論上用 chs / cht 也不錯。</p>
<p>&nbsp;</p>
<p>翻譯一些字串：</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-208 size-full" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/Screenshot-2017-02-20-16.39.16.png" width="872" height="496" /></p>
<p>&nbsp;</p>
<p>翻譯文章：</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-209 size-full" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/Screenshot-2017-02-20-16.41.35.jpg" width="1598" height="1322" /></p>
<p>&nbsp;</p>
<p>編輯文章的介面，會多一個 Languages 區塊：</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-210 size-full" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/Screenshot-2017-02-20-16.46.21.jpg" width="1990" height="1226" /></p>
<p>&nbsp;</p>
<p>最後一個步驟，把語言切換按鈕放進畫面裡，理論上這一步可以省略，可以改用自行輸入的文字區塊的 widgets 加到想要區塊，裡面固定連到某一個語言的首頁。</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-211 size-full" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/Screenshot-2017-02-20-17.01.29.jpg" width="2260" height="1212" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>資料來源：</p>
<p><a href="http://www.wpbeginner.com/beginners-guide/how-to-easily-create-a-multilingual-wordpress-site/">http://www.wpbeginner.com/beginners-guide/how-to-easily-create-a-multilingual-wordpress-site/</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2017/02/how-to-easily-create-a-multilingual-wordpress-site/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Disable Directory Browsing in WordPress</title>
		<link>https://stackoverflow.max-everyday.com/2017/02/how-to-disable-directory-browsing-in-wordpress/</link>
					<comments>https://stackoverflow.max-everyday.com/2017/02/how-to-disable-directory-browsing-in-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Mon, 20 Feb 2017 07:51:26 +0000</pubDate>
				<category><![CDATA[WordPress筆記]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=199</guid>

					<description><![CDATA[發現，預設的apache 參數是允許瀏覽目錄的，...]]></description>
										<content:encoded><![CDATA[<p>發現，預設的apache 參數是允許瀏覽目錄的，修改方法是到 /etc/apache2/sites-available/ 目錄下，把自己的網站增加下面紅字部份的參數：</p>
<p class="p1"><span class="s1"><span class="Apple-converted-space">    </span>&lt;Directory /var/www/html/&gt;</span></p>
<p class="p1"><span style="color: #ff0000;"><strong><span class="s1"><span class="Apple-converted-space">        </span>Options -Indexes</span></strong></span></p>
<p class="p1"><span class="s1"><span class="Apple-converted-space">        </span>AllowOverride All</span></p>
<p class="p1"><span class="s1"><span class="Apple-converted-space">    </span>&lt;/Directory&gt;</span></p>
<p>修改之後的畫面：</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-200" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/Screenshot-2017-02-20-15.46.02.png" alt="" width="1348" height="524" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2017/02/how-to-disable-directory-browsing-in-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>新增指令在Ubuntu 開機時執行</title>
		<link>https://stackoverflow.max-everyday.com/2017/02/ubuntu-boot-command/</link>
					<comments>https://stackoverflow.max-everyday.com/2017/02/ubuntu-boot-command/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Fri, 17 Feb 2017 01:43:41 +0000</pubDate>
				<category><![CDATA[Dropboxlike開發筆記]]></category>
		<category><![CDATA[電腦相關應用]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<category><![CDATA[linux]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=179</guid>

					<description><![CDATA[新增指令到 linux 開機啟動時去執行的作法百...]]></description>
										<content:encoded><![CDATA[
<p>新增指令到 linux 開機啟動時去執行的作法百百種</p>



<h2 class="wp-block-heading">解法1: 放到  /etc/rcS.d/ 目錄下</h2>



<p>這個解法，部份的linux系統無法使用.</p>



<p>先寫一個 .sh 的 shell command, ex: maxserver.sh 放到 /etc/init.d/maxserver.sh</p>



<p>檔案內容如下：</p>



<pre class="wp-block-code"><code>#!/bin/sh
/root/myserver-folder/start.py &amp;>/dev/null &amp;</code></pre>



<p>說明：&amp;>/dev/null &amp; 讓指令丟到背景跑</p>



<hr class="wp-block-separator has-css-opacity"/>



<p>再讓 /etc/rcS.d/S90myserver.sh 連到 /etc/init.d/myserver.sh</p>



<pre class="wp-block-preformatted">ln -s /etc/init.d/myserver.sh /etc/rcS.d/S90myserver.sh</pre>



<p>說明： ln 第1個檔案是隨意找地方放，第2個是放到 &nbsp;/etc/rcS.D/ 目錄裡， S90 是指這個 service 是 啟用中的Serivce 執行的順序是 90 號。</p>



<p>列出所以的serivce</p>



<p>How do you get a list of all starting services?</p>



<pre class="wp-block-code"><code>service --status-all</code></pre>



<p>然後使用指令 <code>service myserver.sh</code> 就可以看到我們的服務了。</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1220" height="558" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/Screenshot-2017-02-17-09.41.39.jpg" alt="" class="wp-image-180"/></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">解法2: Create a systemd Service</h2>



<p>指令:</p>



<pre class="wp-block-code"><code>sudo nano /etc/systemd/system/<span style="background-color: initial; font-family: inherit; font-size: inherit; color: initial;">S15dropboxlike</span>.service</code></pre>



<p>上面的檔案內容:</p>



<figure class="wp-block-table"><table><tbody><tr><td><code>[Unit]<br>Description=S15dropboxlike<br>After=ssh.service network.target<br>SourcePath=/etc/init.d/dropboxlike.sh<br>[Service]<br>User=root<br>Group=root<br>Type=forking<br>Restart=no<br>TimeoutSec=30<br>IgnoreSIGPIPE=no<br>KillMode=process<br>GuessMainPID=no<br>RemainAfterExit=yes<br>ExecStart=/etc/init.d/dropboxlike.sh<br>[Install]<br>WantedBy=multi-user.target</code></td></tr></tbody></table></figure>



<ul class="wp-block-list">
<li><strong>Unit</strong>: It stores the metadata and other information you want to store related to the script.</li>



<li><strong>Service</strong>: Tells the system to execute the desired service, which will run on startup.</li>



<li><strong>Install</strong>: Allows the service to run the WantedBy directory at the startup to handle the dependencies.</li>
</ul>



<p>啟用服務的指令:</p>



<pre class="wp-block-code"><code>chmod 644 /etc/systemd/system/<span style="background-color: initial; font-family: inherit; font-size: inherit; color: initial;">S15dropboxlike</span>.service
systemctl enable <span style="background-color: initial; font-family: inherit; font-size: inherit; color: initial;">S15dropboxlike</span>.service</code></pre>



<p>檢查你的服務狀態:</p>



<pre class="wp-block-code"><code>service <span style="background-color: initial; font-family: inherit; font-size: inherit; color: initial;">S15dropboxlike</span> status</code></pre>



<p>如果你有修改 .service changed on disk. Run &#8216;<code>systemctl daemon-reload</code>&#8216; to reload units. 當然也可以用 reboot 指令.</p>



<p>下面解法3同解法2.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">解法3:</h2>



<p>在 CentOS 可以直接修改 /etc/rc.d/rc.local</p>



<p>以前在 Redhat 及 CentOS 要設定開機自動執行的 Shell Script, 一般都會在檔案 /etc/rc.d/rc.local 加入需要執行的 Shell Script 或指令, 但在 CentOS 7 開始, /etc/rc.d/rc.local 預設權限改為 644, 即沒有執行權限, 為甚麼會這樣, 可以開啟 CentOS 7 的 /etc/rc.d/rc.local 看看, 裡面有 Redhat 的說明:</p>



<pre class="wp-block-code"><code>#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In constrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.</code></pre>



<p>可以看到這個檔案在 RHEL 及 CentOS 7 只為了解決兼容性, Redhat 建議還是自行建立 systemd 服務或者 udev rules 較好, 如果真的需要使用 rc.local, 只要執行 chmod 給予 rc.local 可執行權限即可:</p>



<pre class="wp-block-preformatted"># <code>chmod +x /etc/rc.d/rc.local</code></pre>



<p>執行以上指令後, 下次開機便會自動執行 rc.local 內的指令或 Shell Script.</p>



<hr class="wp-block-separator has-css-opacity"/>



<p>在 <meta charset="utf-8">CentOS ，或是 Ubuntu 18之後的系統，請使用指令 </p>



<pre class="wp-block-preformatted">systemctl enable your-service-name</pre>



<p>會自動產生一個 your-service-name.service 檔案在路徑：/run/systemd/generator.late/ 目錄下。預設不是 run as root ，會造成重開機之後，不是root 權限，無法使用部份系統資源。</p>



<p>預設的  .service 設定值：</p>



<pre class="wp-block-preformatted">[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/init.d/myserver.sh

[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/init.d/myserver.sh start
ExecStop=/etc/init.d/myserver.sh stop</pre>



<hr class="wp-block-separator has-css-opacity"/>



<p>請修改檔案的內容, 並移動到 <meta charset="utf-8">/etc/systemd/system/ 下如：</p>



<p>I have created a service file at /etc/systemd/system/ as follows:</p>



<pre class="wp-block-preformatted">[Unit]
Description=MaxServer
After=ssh.service network.target
SourcePath=/etc/init.d/myserver.sh

[Service]
User=root
Group=root
Type=forking
Restart=no
TimeoutSec=30
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/init.d/myserver.sh start

[Install]
WantedBy=multi-user.target</pre>



<p>接著再使用 systemctl enable myserver 就可以 enable service.</p>



<p> 如果你的 service 需要在 mysql 之後才啟用，請使用這一行：</p>



<pre class="wp-block-code"><code>After=mysql.service</code></pre>



<hr class="wp-block-separator has-css-opacity"/>



<p>在修改好並移檔案路徑之後，請再下一次指令：</p>



<pre class="wp-block-code"><code><meta charset="utf-8">systemctl enable your-service-name</code></pre>



<p>就可以知道，自己的服務有沒有啟用成功，並使用reboot 指令測試是否真的在重啟系統之後，有正確地被自動啟動。</p>



<hr class="wp-block-separator has-css-opacity"/>



<h3 class="wp-block-heading">相關文章</h3>



<p>Centos 7 Script to install as Linux Service<br><a href="https://stackoverflow.max-everyday.com/2017/09/centos-7-script-to-install-as-linux-service/">https://stackoverflow.max-everyday.com/2017/09/centos-7-script-to-install-as-linux-service/</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2017/02/ubuntu-boot-command/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>apache AH00171: Graceful restart requested, doing restart</title>
		<link>https://stackoverflow.max-everyday.com/2017/02/apache-graceful-restart/</link>
					<comments>https://stackoverflow.max-everyday.com/2017/02/apache-graceful-restart/#respond</comments>
		
		<dc:creator><![CDATA[max-stackoverflow]]></dc:creator>
		<pubDate>Tue, 07 Feb 2017 12:46:57 +0000</pubDate>
				<category><![CDATA[電腦相關應用]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<category><![CDATA[letsencrypt]]></category>
		<category><![CDATA[linux]]></category>
		<guid isPermaLink="false">http://stackoverflow.max-everyday.com/?p=100</guid>

					<description><![CDATA[自從安裝了 nginx 之後，apache 的 ...]]></description>
										<content:encoded><![CDATA[<p>自從安裝了 nginx 之後，apache 的 service 每天都自動地被關閉。</p>
<p>用下面指令查看 apache log:</p>
<blockquote><p>tail -n 15 /var/log/apache2/error.log</p></blockquote>
<hr />
<pre>[Tue Feb 07 00:00:35.176718 2017] [mpm_prefork:notice] [pid 1393] AH00171: Graceful restart requested, doing restart
AH00112: Warning: DocumentRoot [/var/lib/letsencrypt/tls_sni_01_page/] does not exist
AH00112: Warning: DocumentRoot [/var/lib/letsencrypt/tls_sni_01_page/] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:443
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:443
[Tue Feb 07 00:00:35.374235 2017] [mpm_prefork:alert] [pid 1393] no listening sockets available, shutting down
[Tue Feb 07 00:00:35.374243 2017] [:emerg] [pid 1393] AH00019: Unable to open logs, exiting
[Tue Feb 07 00:00:43.772645 2017] [core:warn] [pid 7398] AH00098: pid file /var/run/apache2/apache2.pid overwritten -- Unclean shutdown of previous Apache run?
[Tue Feb 07 00:00:43.774845 2017] [mpm_prefork:notice] [pid 7398] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g configured -- resuming normal operations
[Tue Feb 07 00:00:43.774879 2017] [core:notice] [pid 7398] AH00094: Command line: '/usr/sbin/apache2'
[Tue Feb 07 00:05:35.586000 2017] [mpm_prefork:notice] [pid 7398] AH00169: caught SIGTERM, shutting down
</pre>
<hr />
<p>查看 /etc/logrotate.d/apache2</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-101" src="https://stackoverflow.max-everyday.com/wp-content/uploads/2017/02/Screenshot-2017-02-07-19.09.33.jpg" alt="" width="480" height="365" /></p>
<p>先修改上面的 /etc/init.d/apache2 reload 為 /etc/init.d/apache2 restart 之後，明天的 00:00 時候再試看看 apache 會不會又crash.</p>
<hr />
<p>結果隔了一天，還是又掛了，新的 Error Log 還是長一樣：</p>
<pre>[Wed Feb 08 00:00:33.919348 2017] [mpm_prefork:notice] [pid 12057] AH00171: Graceful restart requested, doing restart
AH00112: Warning: DocumentRoot [/var/lib/letsencrypt/tls_sni_01_page/] does not exist
AH00112: Warning: DocumentRoot [/var/lib/letsencrypt/tls_sni_01_page/] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:443
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:443
[Wed Feb 08 00:00:34.029522 2017] [mpm_prefork:alert] [pid 12057] no listening sockets available, shutting down
[Wed Feb 08 00:00:34.029536 2017] [:emerg] [pid 12057] AH00019: Unable to open logs, exiting
[Wed Feb 08 00:00:42.448650 2017] [core:warn] [pid 16845] AH00098: pid file /var/run/apache2/apache2.pid overwritten -- Unclean shutdown of previous Apache run?
[Wed Feb 08 00:00:42.450795 2017] [mpm_prefork:notice] [pid 16845] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g configured -- resuming normal operations
[Wed Feb 08 00:00:42.450817 2017] [core:notice] [pid 16845] AH00094: Command line: '/usr/sbin/apache2'
[Wed Feb 08 00:00:52.544625 2017] [mpm_prefork:notice] [pid 16845] AH00169: caught SIGTERM, shutting down
</pre>
<p>&nbsp;</p>
<hr />
<p>在 /var 目錄下指令：</p>
<blockquote>
<pre class="p1"><span class="s1">grep -r 'tls_sni_01_page' *</span></pre>
</blockquote>
<p class="p1">發現是 <span class="s1">letsencrypt renew 的排程讓 apache2 掛掉。</span></p>
<p class="p1">重新研究一下 certbot 的指令：<br />
<a href="https://certbot.eff.org/docs/using.html#manual">https://certbot.eff.org/docs/using.html#manual</a></p>
<p>&nbsp;</p>
<p class="p1">發現使用 standalone 會啟動一個暫時的 web server  來取得憑證。</p>
<p><a href="https://certbot.eff.org/docs/using.html#standalone">https://certbot.eff.org/docs/using.html#standalone</a></p>
<pre>standalone:
  Spin up a temporary webserver</pre>
<hr />
<p class="p1">certonly 參數如下：</p>
<pre>certonly:
  Options for modifying how a cert is obtained

  <span style="color: #ff0000;">--tls-sni-01-port</span> TLS_SNI_01_PORT
                        Port used during tls-sni-01 challenge. This only
                        affects the port Certbot listens on. A conforming ACME
                        server will still attempt to connect on port 443.
                        (default: 443)
  <span style="color: #ff0000;">--http-01-port</span> HTTP01_PORT
                        Port used in the http-01 challenge.This only affects
                        the port Certbot listens on. A conforming ACME server
                        will still attempt to connect on port 80. (default:
                        80)
  --csr CSR             Path to a Certificate Signing Request (CSR) in DER or
                        PEM format. Currently --csr only works with the
                        'certonly' subcommand. (default: None)
</pre>
<hr />
<p>&nbsp;</p>
<blockquote>
<pre>certbot certonly --standalone -d example.com <span style="color: #ff0000;">--tls-sni-01-port 443 --http-01-port 80</span></pre>
</blockquote>
<p>新的版本的 certbot 用起來更簡單：</p>
<blockquote>
<pre>certbot certonly --cert-name your-domain-name</pre>
</blockquote>
<p>&nbsp;</p>
<p>nginx 請修改 config 裡：</p>
<pre><span class="Comment">  # 啟用 SSL</span>
  <span class="Identifier">ssl</span> <span class="Constant">on</span>;

<span class="Comment">  # 設定 SSL 憑證</span>
  <span class="Identifier">ssl_certificate</span> /etc/letsencrypt/live/your-domain-name/fullchain.pem;
  <span class="Identifier">ssl_certificate_key</span> /etc/letsencrypt/live/your-domain-name/privkey.pem;

</pre>
<p>&nbsp;</p>
<p>官方教學：</p>
<p><a href="https://certbot.eff.org/lets-encrypt/ubuntuxenial-other">https://certbot.eff.org/lets-encrypt/ubuntuxenial-other</a></p>
<p>&nbsp;</p>
<hr />
<h4>相關文章：</h4>
<p>How to know why my server crashes?<br />
<a href="http://askubuntu.com/questions/405655/how-to-know-why-my-server-crashes">http://askubuntu.com/questions/405655/how-to-know-why-my-server-crashes</a></p>
<p>Apache reload/graceful restart causes Apache segfault<br />
<a href="https://talk.plesk.com/threads/apache-reload-graceful-restart-causes-apache-segfault.335534/">https://talk.plesk.com/threads/apache-reload-graceful-restart-causes-apache-segfault.335534/</a></p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://stackoverflow.max-everyday.com/2017/02/apache-graceful-restart/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
