-
-
Save holys/3897371 to your computer and use it in GitHub Desktop.
dl.cuoluo.me nginx config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name dl.cuoluo.me; | |
location / { | |
proxy_redirect off; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_pass http://dl.dropbox.com/u/1812807/dl.cuoluo.me/index.html; | |
if ($request_method = POST) { | |
content_by_lua ' | |
ngx.req.read_body() | |
local args = ngx.req.get_post_args() | |
ngx.header.content_type = "text/plain"; | |
if not args["uid"] or not string.find(args["uid"], "^%d+$") or string.len(args["uid"]) > 20 then | |
ngx.say("0") | |
return | |
end | |
local d = "/home/natalie/dlcl/bind" | |
local c = "ls "..d.." | grep _"..args["uid"].."$" | |
local f = io.popen(c) | |
local r = f:read("*l") | |
if not r then | |
if not args["domain"] or args["domain"] == "" then | |
ngx.say("not binded") | |
elseif not string.find(args["domain"], "^%w+$") or string.find(args["domain"], "^%d+$") or string.len(args["domain"]) > 30 then | |
ngx.say("bad domain") | |
else | |
local check = "ls "..d.." | grep ^"..args["domain"].."_" | |
local f = io.popen(check) | |
local check_r = f:read("*l") | |
if check_r then | |
ngx.say("binded") | |
return | |
end | |
local tc = "touch "..d.."/"..args["domain"].."_"..args["uid"] | |
os.execute(tc) | |
ngx.say("1") | |
end | |
else | |
local l = string.len(args["uid"]) + 2 | |
ngx.say(string.sub(r, 1, -1*l)) | |
end | |
'; | |
} | |
} | |
location ~* ^/(\w*[a-z]+\w*)(/(.*))? { | |
root "/home/natalie/dlcl"; | |
set $custom_name $1; | |
set_by_lua $res " | |
local d = '/home/natalie/dlcl/bind' | |
local c = 'ls '..d..' | grep ^'..ngx.arg[1]..'_' | |
local f = io.popen(c) | |
local r = f:read('*l') | |
if not r then return '0' end | |
local l = string.len(ngx.arg[1]) + 2 | |
return string.sub(r,l,-1) | |
" $custom_name; | |
if ($res = '0') { | |
return 404; | |
break; | |
} | |
set $user_public http://dl.dropbox.com/u/$res/cuoluo_$custom_name/$3; | |
proxy_redirect off; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_pass $user_public; | |
set $index index.html; | |
rewrite ^\/(\w+)$ $fastcgi_script_name/$index last; | |
rewrite ^.*\/$ $fastcgi_script_name$index last; | |
} | |
location ~ ^/(\d+)(/(.*))? { | |
set $userid $1; | |
set $user_public http://dl.dropbox.com/u/$userid/cuoluo/$3; | |
proxy_redirect off; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_pass $user_public; | |
set $index index.html; | |
rewrite ^\/(\d+)$ $fastcgi_script_name/$index last; | |
rewrite ^.*\/$ $fastcgi_script_name$index last; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment