<?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>Nginx | SDT 攻城獅區</title>
	<atom:link href="https://sdt.hameba.tw/tag/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>https://sdt.hameba.tw</link>
	<description>由Steven, Der, Ted 三位高級打字員所組成，是三位工程師(攻城獅)所維護的技術分享平台，或許偶爾會分享一些日常，有任何問題或是錯誤的部分，歡迎留言告訴我們！</description>
	<lastBuildDate>Thu, 19 Dec 2019 22:16:58 +0800</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.3</generator>

<image>
	<url>https://sdt.hameba.tw/wp-content/uploads/2020/02/hameba_favicon-150x150.png</url>
	<title>Nginx | SDT 攻城獅區</title>
	<link>https://sdt.hameba.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Nginx 訪問靜態文件</title>
		<link>https://sdt.hameba.tw/337/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nginx-%25e8%25a8%25aa%25e5%2595%258f%25e9%259d%259c%25e6%2585%258b%25e6%2596%2587%25e4%25bb%25b6</link>
				<comments>https://sdt.hameba.tw/337/#respond</comments>
				<pubDate>Tue, 17 Dec 2019 13:35:29 +0000</pubDate>
		<dc:creator><![CDATA[Hsu Steven]]></dc:creator>
				<category><![CDATA[System]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[靜態文件]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=337</guid>
				<description><![CDATA[<p>如何設定nginx，訪問靜態文件？ 因為google adsense 需要在網域上訪問 ads.txt檔案，  &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/337/" class="more-link">閱讀全文<span class="screen-reader-text">〈Nginx 訪問靜態文件〉</span></a></p>
The post <a href="https://sdt.hameba.tw/337/">Nginx 訪問靜態文件</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>如何設定nginx，訪問靜態文件？</p>
<p>因為google adsense 需要在網域上訪問 ads.txt檔案，</p>
<p><span id="more-337"></span></p>
<p>剛好有找到一些方法提供給大家，</p>
<ul>
<li>按目錄匹配 server塊內添加如下內容：</li>
</ul>
<p></p><pre class="crayon-plain-tag">server {
    .
    location ^~ /jsonfolder/ {
        root /home/www/;
    }
    .
}</pre><p>如果使用post方式將無法正確返回，需要修改nginx的源碼src/http/modules/ngx_http_static_module.c</p>
<p>移除以下內容</p><pre class="crayon-plain-tag">if (r-&gt;method &amp; NGX_HTTP_POST) {
    return NGX_HTTP_NOT_ALLOWED;
}</pre><p>執行make命令重新編譯，執行cp objs/nginx /usr/local/nginx/sbin/nginx，將objs目錄下生成nginx命令拷貝到nginx安裝目錄sbin目錄下，重啟即可。(此方法未驗證)</p>
<ul>
<li>按文件後綴匹配</li>
</ul>
<p></p><pre class="crayon-plain-tag">server {
    .
    location ~ \.(txt|json)$ {
        root /home/www/;
    }
    .
}</pre><p>匹配txt和json的文件就會被顯示出來</p>
<p>Reference</p>
<p><a href="https://blog.csdn.net/ocean20/article/details/80738798">https://blog.csdn.net/ocean20/article/details/80738798</a></p>The post <a href="https://sdt.hameba.tw/337/">Nginx 訪問靜態文件</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/337/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Nginx 增加安全性</title>
		<link>https://sdt.hameba.tw/193/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nginx-%25e5%25a2%259e%25e5%258a%25a0%25e5%25ae%2589%25e5%2585%25a8%25e6%2580%25a7</link>
				<comments>https://sdt.hameba.tw/193/#respond</comments>
				<pubDate>Thu, 05 Dec 2019 06:22:45 +0000</pubDate>
		<dc:creator><![CDATA[Hsu Steven]]></dc:creator>
				<category><![CDATA[System]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx.conf]]></category>

		<guid isPermaLink="false">http://192.168.100.203/?p=193</guid>
				<description><![CDATA[<p>基本安裝完Nginx 都是default 當出現404 403畫面最底部就會顯示nginx版本 其實這也有告訴 &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/193/" class="more-link">閱讀全文<span class="screen-reader-text">〈Nginx 增加安全性〉</span></a></p>
The post <a href="https://sdt.hameba.tw/193/">Nginx 增加安全性</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>基本安裝完Nginx 都是default</p>
<p>當出現404 403畫面最底部就會顯示nginx版本</p>
<p><span id="more-193"></span></p>
<p>其實這也有告訴外面的人你所使用的server application 版本，透過此版本要查到相關漏洞是非常容易。</p>
<p>所以可以透過幾個步驟增加安全</p><pre class="crayon-plain-tag"># 修改nginx設定檔案 每個os路徑不一樣
$ sudo nano /etc/nginx/nginx.conf

#在http 內添加server_tokens off; 此可以擋掉版本洩漏問題
http {
   ...
   server_tokens off;
   ...
}</pre><p>&nbsp;</p>
<p>另外可以參考此篇<a href="/?p=184" target="_blank" rel="noopener noreferrer">Raspberry pi 安裝 Nginx及擴充module</a></p>
<p>當完成後module包裡面就有header filter模組</p><pre class="crayon-plain-tag"># 修改nginx設定檔案
$ sudo nano /etc/nginx/nginx.conf

# nginx.conf 增加以下內容

# 引用ngx_http_headers_more_filter_module
load_module modules/ngx_http_headers_more_filter_module.so;

http {
    ...
    more_clear_headers Server;
    ...
}</pre><p>每次請求(request) header也會藏有Server資訊也是會產生洩漏資訊的問題</p>
<p>Reference</p>
<p><a href="https://www.getpagespeed.com/server-setup/nginx/how-to-remove-the-server-header-in-nginx">https://www.getpagespeed.com/server-setup/nginx/how-to-remove-the-server-header-in-nginx</a></p>
<div id="gtx-trans">
<div class="gtx-trans-icon"></div>
</div>The post <a href="https://sdt.hameba.tw/193/">Nginx 增加安全性</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/193/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Nginx Status 資訊視覺化</title>
		<link>https://sdt.hameba.tw/183/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nginx-status-%25e8%25b3%2587%25e8%25a8%258a%25e8%25a6%2596%25e8%25a6%25ba%25e5%258c%2596</link>
				<comments>https://sdt.hameba.tw/183/#respond</comments>
				<pubDate>Wed, 04 Dec 2019 07:39:26 +0000</pubDate>
		<dc:creator><![CDATA[Hsu Steven]]></dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Grafana]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx_vts_exporter]]></category>
		<category><![CDATA[nginx-module-vts]]></category>
		<category><![CDATA[Prometheus]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Raspbian]]></category>

		<guid isPermaLink="false">http://192.168.100.203/?p=183</guid>
				<description><![CDATA[<p>這篇主要整理作法步驟，此圖講解非常清楚 Raspberry pi 安裝 Nginx及擴充module Rasp &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/183/" class="more-link">閱讀全文<span class="screen-reader-text">〈Nginx Status 資訊視覺化〉</span></a></p>
The post <a href="https://sdt.hameba.tw/183/">Nginx Status 資訊視覺化</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p><img class="alignnone size-medium" src="https://miro.medium.com/max/964/1*GRUtK24FDYpR1Dc3jGG40A.png" width="482" height="803" /></p>
<p><span id="more-183"></span></p>
<p>這篇主要整理作法步驟，此圖講解非常清楚</p>
<ol>
<li><a href="/?p=184" target="_blank" rel="noopener noreferrer">Raspberry pi 安裝 Nginx及擴充module</a></li>
<li><a href="/?p=146" target="_blank" rel="noopener noreferrer">Raspberry pi nginx 增加模組 nginx-module-vts</a></li>
<li><a href="/?p=171" target="_blank" rel="noopener noreferrer">Raspberry pi 安裝 Nginx_vts_exporter</a></li>
<li><a href="/?p=176" target="_blank" rel="noopener noreferrer">Raspberry pi 安裝 Prometheus</a></li>
<li><a href="/?p=180" target="_blank" rel="noopener noreferrer">Raspberry pi 安裝 Grafana</a></li>
</ol>
<p>Reference</p>
<p><a href="https://medium.com/@shevtsovav/ready-for-scraping-nginx-metrics-nginx-vts-exporter-prometheus-grafana-26c14816ae7c">https://medium.com/@shevtsovav/ready-for-scraping-nginx-metrics-nginx-vts-exporter-prometheus-grafana-26c14816ae7c</a></p>
<p><a href="https://grafana.com/blog/2019/08/22/homelab-security-with-ossec-loki-prometheus-and-grafana-on-a-raspberry-pi/">https://grafana.com/blog/2019/08/22/homelab-security-with-ossec-loki-prometheus-and-grafana-on-a-raspberry-pi/</a></p>
<p>&nbsp;</p>
<div id="gtx-trans">
<div class="gtx-trans-icon"></div>
</div>The post <a href="https://sdt.hameba.tw/183/">Nginx Status 資訊視覺化</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/183/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Raspberry pi 安裝 Nginx及擴充module</title>
		<link>https://sdt.hameba.tw/184/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=raspberry-pi-%25e5%25ae%2589%25e8%25a3%259d-nginx%25e5%258f%258a%25e6%2593%25b4%25e5%2585%2585module</link>
				<comments>https://sdt.hameba.tw/184/#respond</comments>
				<pubDate>Wed, 04 Dec 2019 07:38:05 +0000</pubDate>
		<dc:creator><![CDATA[Hsu Steven]]></dc:creator>
				<category><![CDATA[System]]></category>
		<category><![CDATA[Module]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Raspbian]]></category>

		<guid isPermaLink="false">http://192.168.100.203/?p=184</guid>
				<description><![CDATA[<p>特別寫這篇主要是因為可以透過apt-get install方式 直接擴充基本的module ndk_http_ &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/184/" class="more-link">閱讀全文<span class="screen-reader-text">〈Raspberry pi 安裝 Nginx及擴充module〉</span></a></p>
The post <a href="https://sdt.hameba.tw/184/">Raspberry pi 安裝 Nginx及擴充module</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>特別寫這篇主要是因為可以透過apt-get install方式</p>
<p>直接擴充基本的module</p>
<p><span id="more-184"></span></p>
<p>ndk_http_module.so ngx_http_headers_more_filter_module.so<br />
ngx_http_auth_pam_module.so ngx_http_image_filter_module.so ngx_http_xslt_filter_module.so<br />
ngx_http_cache_purge_module.so ngx_http_lua_module.so ngx_mail_module.so<br />
ngx_http_dav_ext_module.so ngx_http_perl_module.so ngx_nchan_module.so<br />
ngx_http_echo_module.so ngx_http_subs_filter_module.so ngx_stream_module.so<br />
ngx_http_fancyindex_module.so ngx_http_uploadprogress_module.so<br />
ngx_http_geoip_module.so ngx_http_upstream_fair_module.so</p>
<p>建議使用此安裝指令方式</p><pre class="crayon-plain-tag">$ sudo apt-get nginx nginx-extras nginx-full</pre><p>&nbsp;</p>
<div id="gtx-trans">
<div class="gtx-trans-icon"></div>
</div>The post <a href="https://sdt.hameba.tw/184/">Raspberry pi 安裝 Nginx及擴充module</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/184/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Nginx 訪問控制 allow、deny</title>
		<link>https://sdt.hameba.tw/165/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nginx-%25e8%25a8%25aa%25e5%2595%258f%25e6%258e%25a7%25e5%2588%25b6-allow%25e3%2580%2581deny</link>
				<comments>https://sdt.hameba.tw/165/#respond</comments>
				<pubDate>Wed, 04 Dec 2019 03:16:43 +0000</pubDate>
		<dc:creator><![CDATA[Hsu Steven]]></dc:creator>
				<category><![CDATA[System]]></category>
		<category><![CDATA[allow]]></category>
		<category><![CDATA[deny]]></category>
		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://192.168.100.203/?p=165</guid>
				<description><![CDATA[<p>除了透過防火牆控制網頁的訪問方式外 進階可以再加入使用Nginx來管控 因為有些網址有url path的管控機 &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/165/" class="more-link">閱讀全文<span class="screen-reader-text">〈Nginx 訪問控制 allow、deny〉</span></a></p>
The post <a href="https://sdt.hameba.tw/165/">Nginx 訪問控制 allow、deny</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>除了透過防火牆控制網頁的訪問方式外</p>
<p>進階可以再加入使用Nginx來管控</p>
<p><span id="more-165"></span></p>
<p>因為有些網址有url path的管控機制跟ip網域有關</p>
<p>以此為例</p><pre class="crayon-plain-tag">location / {
  deny  192.168.1.1;
  allow 192.168.1.0/24;
  allow 10.1.1.0/16;
  allow 2001:0db8::/32;
  deny  all;
}</pre><p>從上到下的順序，類似iptables。是否符合我們訂製的規範。如上的例子先禁止了192.16.1.1，接下來允許了3個網段，其中包含了一個ipv6，最後未匹配的IP全部禁止訪問.</p>
<p>deny all; 很重要如果沒有加上，上方所寫的allow 大致也不會有用。</p>
<p>Reference</p>
<p><a href="http://www.ttlsa.com/linux/nginx-modules-ngx_http_access_module/">http://www.ttlsa.com/linux/nginx-modules-ngx_http_access_module/</a></p>
<p>&nbsp;</p>
<div id="gtx-trans">
<div class="gtx-trans-icon"></div>
</div>The post <a href="https://sdt.hameba.tw/165/">Nginx 訪問控制 allow、deny</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/165/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Raspberry pi nginx 增加模組 nginx-module-vts</title>
		<link>https://sdt.hameba.tw/146/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=raspberry-pi-4-nginx-%25e5%25a2%259e%25e5%258a%25a0%25e6%25a8%25a1%25e7%25b5%2584-nginx-module-vts</link>
				<comments>https://sdt.hameba.tw/146/#respond</comments>
				<pubDate>Sat, 30 Nov 2019 08:25:12 +0000</pubDate>
		<dc:creator><![CDATA[Hsu Steven]]></dc:creator>
				<category><![CDATA[System]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[nginx-module-vts]]></category>
		<category><![CDATA[pi 4]]></category>
		<category><![CDATA[Raspberry Pi]]></category>

		<guid isPermaLink="false">http://192.168.100.203/?p=146</guid>
				<description><![CDATA[<p>硬體:Raspberry pi 4 OS:Raspbian Buster Version:September  &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/146/" class="more-link">閱讀全文<span class="screen-reader-text">〈Raspberry pi nginx 增加模組 nginx-module-vts〉</span></a></p>
The post <a href="https://sdt.hameba.tw/146/">Raspberry pi nginx 增加模組 nginx-module-vts</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>硬體:Raspberry pi 4</p>
<p>OS:Raspbian Buster</p>
<p><span id="more-146"></span></p>
<p>Version:September 2019</p>
<p>Release date:2019-09-26</p><pre class="crayon-plain-tag"># 先補足相關套件
$ sudo apt-get install libpcre3 libpcre3-dev openssl libssl-dev libxslt-dev libgd-dev libgeoip-dev libgd2-xpm-dev libgd2-xpm libgd2-xpm-dev libperl-dev

# 查詢nginx 版本
$ sudo nginx -v
#nginx version: nginx/1.14.2

# 下載對應版本
$ wget 'http://nginx.org/download/nginx-1.14.2.tar.gz'
# 解壓縮
$ tar -xzvf nginx-1.14.2.tar.gz

# 下載nginx_module_vts
$ git clone git://github.com/vozlt/nginx-module-vts.git

# 查詢目前nginx setting
$ sudo nginx -V
# 出現如下資訊
# ./configure --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-7du1qr/nginx-1.14.2=.
# -fstack-protector-strong -Wformat -Werror=format-security -fPIC 簡略不列出... 
# --with-stream_ssl_module --with-stream_ssl_preread_module --with-mail=dynamic --with-mail_ssl_module

#進入nginx-1.14.2目錄
$ cd nginx-1.14.2

#輸入剛剛查詢到的資訊，在最後面補上 --add-dynamic-module=../nginx-module-vts
$ ./configure --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-7du1qr/nginx-1.14.2=. 中間簡略不列出
 --with-mail=dynamic --with-mail_ssl_module --add-dynamic-module=../nginx-module-vts

#make 製作出檔案
$ make

$ cd /usr/sbin/

# 備份原本的nginx
$ sudo copy nginx nginx.old

# 把剛剛製作出來的nginx複製過來
$ sudo cp ~/nginx-1.14.2/objs/nginx .

# 重啟nginx 
$ sudo service nginx restart

#查詢是否有加入模組
$ sudo nginx -V
#正常會顯示出來最後一行有此句 --add-dynamic-module=../nginx-module-vts

# 將產生的模組放進系統預設地方
sudo cp ~/nginx-1.14.2/objs/ngx_http_vhost_traffic_status_module.so /usr/lib/nginx/modules/

$ sudo nano /etc/nginx/nginx.conf

# 在此兩句下面
# pid /run/nginx.pid;
# include /etc/nginx/modules-enabled/*.conf;
# 新增以下此句
# load_module modules/ngx_http_vhost_traffic_status_module.so;
# http{} 新增此句
# vhost_traffic_status_zone;
# 存擋離開

# 測試nginx是否設定有問題
$ sudo nginx -t

# 測試無誤後，新增網址觀看路徑
$ sudo nano /etc/nginx/sites-enabled/status.conf
# 內容如下
# server {
#	listen 9999;
#	location / {
#		vhost_traffic_status_display;
#		vhost_traffic_status_display_format html;
#	}
#}
# 完成存擋離開

# 重啟nginx
$ sudo service nginx restart</pre><p>以上成功完成後</p>
<p>開啟 http://localhost:9999/ 網址</p>
<p>即可以看到nginx 狀況 如下圖</p>
<p><img class="alignleft size-medium" src="https://cloud.githubusercontent.com/assets/3648408/23890539/a4c0de18-08d5-11e7-9a8b-448662454854.png" alt="nginx module vts 示意圖" width="1096" height="955" /></p>
<div id="gtx-trans">
<div class="gtx-trans-icon"></div>
</div>The post <a href="https://sdt.hameba.tw/146/">Raspberry pi nginx 增加模組 nginx-module-vts</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/146/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
	</channel>
</rss>
