Skip to content

Instantly share code, notes, and snippets.

@yungke
yungke / http_to_https
Last active August 29, 2015 14:19
Nginx 下 301 http 轉向 https 設定
server {
listen 80;
server_name you.domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name you.domain.com;
[….]
@yungke
yungke / nginx_pagespeed_1
Last active August 29, 2015 14:19
Nginx 下安裝 PageSpeed module
sudo yum install gcc-c++ pcre-dev pcre-devel zlib-devel make unzip
@yungke
yungke / lnnmp-memcached.sh
Created April 17, 2015 05:11
LNMP 1.1 php 5.23 環境 memcaches 升級腳本
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install lnmp"
exit 1
fi
@yungke
yungke / w3tcnginx.conf
Created April 18, 2015 14:31
Nginx W3TC 緩存設定檔
# BEGIN W3TC Browser Cache
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location ~ \.(css|htc|less|js|js2|js3|js4)$ {
expires 31536000s;
add_header Pragma "public";
add_header Cache-Control "max-age=31536000, public";
add_header X-Powered-By "W3 Total Cache/0.9.4.1";
}
location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
@yungke
yungke / pagespeed_handler.conf
Created April 18, 2015 17:11
ngx_pagespeed config 一般網路版本
#ngx_pagespeed config
pagespeed FileCachePath /var/ngx_pagespeed_cache; # Use tmpfs for best results.
pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters local_storage_cache;
pagespeed EnableFilters collapse_whitespace,remove_comments;
pagespeed EnableFilters outline_css;
pagespeed EnableFilters flatten_css_imports;
pagespeed EnableFilters move_css_above_scripts;
pagespeed EnableFilters move_css_to_head;
pagespeed EnableFilters outline_javascript;
@yungke
yungke / pagespeed_corefilters.conf
Last active August 29, 2015 14:19
ngx_pagespeed config 基本 / 進階設置
#ngx_pagespeed config
# enable CoreFilters
pagespeed RewriteLevel CoreFilters;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# disable particular filter(s) in CoreFilters
pagespeed DisableFilters rewrite_images;
# enable additional filter(s) selectively
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters insert_dns_prefetch;
@yungke
yungke / upgrade_nginx.sh
Created April 18, 2015 17:24
LNMP 1.1 nginx 升級 + ngx_pagespeed + spdy 腳本
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install lnmp"
exit 1
fi
@yungke
yungke / .htaccess
Created April 19, 2015 09:25
w3tc for Apache
# BEGIN W3TC Browser Cache
<IfModule mod_mime.c>
AddType text/css .css
AddType text/x-component .htc
AddType application/x-javascript .js
AddType application/javascript .js2
AddType text/javascript .js3
AddType text/x-js .js4
AddType text/html .html .htm
AddType text/richtext .rtf .rtx
@yungke
yungke / discuz_application.php
Created April 24, 2015 04:08
Discuz X3.2 facebook 連結至 discuz 的錯誤修正
private function _xss_check() {
$_SERVER['REQUEST_URI'] = preg_replace("/(&|\?)fb_action(.*?)$/i", "", $_SERVER['REQUEST_URI']);
$temp = strtoupper(urldecode(urldecode($_SERVER['REQUEST_URI'])));
if(strpos($temp, '<') !== false || strpos($temp, '"') !== false || strpos($temp, 'CONTENT-TRANSFER-ENCODING') !== false) {
system_error('request_tainting');
}
return true;
}
@yungke
yungke / X-Page-Speed header
Last active August 29, 2015 14:20
Wp-ffpc 在 Nginx 的 conf 檔案
[root@vps ~]# curl -I http://yourDomain.com/
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 27 Apr 2015 02:51:40 GMT
Content-Type: text/html;charset=utf-8
Connection: keep-alive
Vary: Accept-Encoding
Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0
Pragma: no-cache
Expires: Mon, 27 Apr 2015 02:51:40 GMT