8 月 25 2015
調整 Apache HTTPD & Apache Tomcat & nginx 的 content cache & compression
前陣子調整了一些 Apache HTTPD & Tomcat & nginx 的 cache 機制與內容壓縮機制,稍微紀錄一下。
Apache HTTPD 的 cache:
<IfModule mod_expires.c> ExpiresActive On ExpiresByType image/gif "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType text/css "access plus 1 month" </IfModule>
Apache HTTPD 的壓縮:
<IfModule mod_deflate.c> DeflateCompressionLevel 9 AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php AddOutputFilter DEFLATE js css </IfModule>
Apache Tomcat 的 cache(在 application 的 web.xml 做調整):
<filter> <filter-name>ExpiresFilter</filter-name> <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class> <init-param> <param-name>ExpiresByType image</param-name> <param-value>access plus 1 month</param-value> </init-param> <init-param> <param-name>ExpiresByType text/css</param-name> <param-value>access plus 1 month</param-value> </init-param> <init-param> <param-name>ExpiresByType application/javascript</param-name> <param-value>access plus 1 month</param-value> </init-param> </filter> <filter-mapping> <filter-name>ExpiresFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> </filter-mapping>
Apache Tomcat 的壓縮(在 conf/server.xml 做調整):
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" compression="on" compressableMimeType="text/html,text/xml,text/plain,text/css,application/javascript" redirectPort="8443" />
nginx 的 cache(在 server tag 內做調整):
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires 1M; }
nginx 的壓縮(在 http tag 內做調整):
gzip_vary on; gzip_proxied any; gzip_comp_level 9; gzip_buffers 8 32k; gzip_http_version 1.0; gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;
大概就調這些,其他多媒體檔案就看需求了…
2 月 22 2016
改用 Let’s Encrypt 的 certificates
之前都在用 StartSSL 的免費 certificate,雖知道有 Let’s Encrypt,但因手邊幾乎都轉用 nginx,遲遲沒下手。
約莫一週前 zeroplex 丟了這個網頁:「Why I stopped using StartSSL (Hint: it involves a Chinese company)」,三、四天前 DK 大神也撰文提及,就決定趁週末沒什麼事來動工…
用 DK 大神在一個月前撰文提過的 dehydrated 這個 GitHub 專案可以輕鬆搞定,步驟大致如下…
我記得 Let’s Encrypt 的 certificate 要在 90 天內 renew,所以 cron job 這樣放:
Updated : letsencrypt.sh 改為 dehydrated 。
By Joe Horn • WWW 0 • Tags: certificate, dehydrated, HTTPS, Let's Encrypt, letsencrypt.sh, nginx, SSL, StartSSL