Skip to content

Instantly share code, notes, and snippets.

View notsobad's full-sized avatar

notsobad notsobad

View GitHub Profile
try {
if (!window.___is3b) {
window.___is3b = "prepare"
}
function test3b() {
window.___is3b = "loading";
var c = navigator.userAgent.toLowerCase();
if (!c.match(/msie ([\d.]+)/)) {
window.___is3b = "false";
@notsobad
notsobad / proxy_cache.conf
Created February 26, 2014 03:43
Proxy cache sample.
proxy_cache_path /data/proxy_cache levels=1:2 keys_zone=ui-cache:10m max_size=2048m;
server {
# api proxy
listen 80;
# Force cache post data for 3 days.
location /xxxx.php {
proxy_cache_key "$scheme://$host$request_uri|$request_body";
proxy_cache_valid 200 3d;
proxy_cache ui-cache;
@notsobad
notsobad / nginx-lua-tip.md
Last active August 29, 2015 13:57
By notsobad.

TIPS

  • 修改完nginx配置之后,要运行nginx -t检查配置
  • lua中的print以notice日志打印到error_log中,所以需要开启notice日志,error_log /var/log/nginx/error.log notice; 参考: http://wiki.nginx.org/HttpLuaModuleZh#print
  • body_filter_by_lua可以用于修改响应, ngx.arg[1]为body正文,由于响应可能会分成多段,所以lua代码可能会触发多次,ngx.arg[2]为eof标记,当正文结束时,ngx.arg[2]为true
  • 设置lua_code_cache off,可以禁用*_by_lua_file的lua缓存,编辑lua代码之后,不需要reload nginx即可生效,这个指令对于content_by_lua之类写在nginx配置文件内部的lua代码无效。
# backup config, save local.
tar czvf /tmp/openwrt.tgz /etc/config

# reset
mtd -r erase rootfs_data
@notsobad
notsobad / nginx-redirect.conf
Created March 24, 2014 15:31
Redirect all request to a server except static files.
server {
listen 80 ;
server_name 127.0.0.1;
client_header_timeout 60s;
client_body_timeout 30s;
send_timeout 60s;
#access_log /var/log/redirect.access_log redirect;
@notsobad
notsobad / .tmux.conf
Last active August 29, 2015 14:03
My tmux.conf
# remap prefix to Control + a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# Base
set -g history-limit 30000
set -g status-justify left
set-window-option -g utf8 on
set-window-option -g automatic-rename on
@notsobad
notsobad / fabfile.py
Created July 26, 2014 01:58
Use fabric and svn to deploy code to multi servers.
import os
from fabric.api import task, run, env, cd
'''
* fab version
* fab deploy user:password:version
* fab reload_ui
'''
__author__ = 'notsobad'
@notsobad
notsobad / allow_ip.conf
Created August 21, 2014 09:21
Get real ip under proxy, and only alow some ip to access.
server {
listen 80;
location /secret {
access_by_lua '
local function string_starts(String,Start)
return string.sub(String,1,string.len(Start)) == Start
end
local ip = nil
local cdn_ip = ngx.req.get_headers()["X-Real-Forwarded-For"]
if cdn_ip then