Last active
December 31, 2015 05:29
-
-
Save ijin/7941214 to your computer and use it in GitHub Desktop.
svfes201311_base_nginx.conf
This file contains hidden or 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
#user nobody; | |
worker_processes 1; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
log_format main '$request_time $remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for" $upstream_response_time'; | |
#access_log logs/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
#keepalive_timeout 0; | |
keepalive_timeout 65; | |
gzip on; | |
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; | |
client_max_body_size 100M; | |
client_header_buffer_size 1k; | |
large_client_header_buffers 8 8k; | |
server { | |
listen 8081; | |
access_log logs/post.access.log main; | |
location /wp-comments-post2.php { | |
return 201; | |
} | |
location /sleep { | |
echo_sleep 0.005; | |
} | |
location /test { | |
content_by_lua ' | |
-- ngx.var.uri | |
ngx.say(ngx.var.host) | |
ngx.say("http:") | |
ngx.say(ngx.var.http_host) | |
ngx.say("said") | |
--return ngx.redirect("http://210.140.145.151/?p=#comment-" .. ngx.var.uri , 302) | |
'; | |
} | |
location ~ /wp-comments-post.php { | |
content_by_lua ' | |
ngx.req.read_body() | |
local args = ngx.req.get_post_args() | |
if not args then | |
ngx.say("failed to get post args: ", err) | |
return | |
end | |
local quoted_comment_post_id = "0" | |
local quoted_comment_author = [[""]] | |
local quoted_comment_author_email = [[""]] | |
local quoted_comment_author_url = [[""]] | |
local quoted_comment_author_ip = "127" | |
local quoted_comment_content = [[""]] | |
local quoted_comment_karma = "0" | |
local quoted_comment_approved = "1" | |
local quoted_comment_agent = "0" | |
local quoted_comment_type = "0" | |
local quoted_comment_parent = [[""]] | |
local quoted_user_id = "0" | |
if args["comment_post_ID"] then | |
quoted_comment_post_id = ngx.quote_sql_str(ngx.unescape_uri(args["comment_post_ID"])) | |
end | |
if args["author"] then | |
quoted_comment_author = ngx.quote_sql_str(ngx.unescape_uri(args["author"])) | |
end | |
if args["email"] then | |
quoted_comment_author_email = ngx.quote_sql_str(ngx.unescape_uri(args["email"])) | |
end | |
if args["comment_author_url"] then | |
quoted_comment_author_url = ngx.quote_sql_str(ngx.unescape_uri(args["comment_author_url"])) | |
end | |
if args["comment_author_ip"] then | |
quoted_comment_author_ip = ngx.quote_sql_str(ngx.unescape_uri(args["comment_author_ip"])) | |
end | |
if args["comment_agent"] then | |
quoted_comment_agent = ngx.quote_sql_str(ngx.unescape_uri(args["comment_agent"])) | |
end | |
if args["comment"] then | |
quoted_comment_content = ngx.quote_sql_str(ngx.unescape_uri(args["comment"])) | |
end | |
if args["comment_parent"] then | |
quoted_comment_parent = ngx.quote_sql_str(ngx.unescape_uri(args["comment_parent"])) | |
end | |
local mysql = require "resty.mysql" | |
local db, err = mysql:new() | |
db:connect{ | |
host = "127.0.0.1", | |
port = 3306, | |
database = "wordpress", | |
user = "csf", | |
password = "csfp@ssw0rd" | |
} | |
query = "INSERT INTO `wp_comments` (`comment_post_ID`,`comment_author`," | |
.. "`comment_author_email`,`comment_author_url`,`comment_author_IP`," | |
.. "`comment_date`,`comment_date_gmt`,`comment_content`,`comment_karma`," | |
.. "`comment_approved`,`comment_agent`,`comment_type`,`comment_parent`," | |
.. "`user_id`) VALUES (" | |
.. quoted_comment_post_id .. "," .. quoted_comment_author .. "," | |
.. quoted_comment_author_email .. "," .. quoted_comment_author_url .. "," | |
.. quoted_comment_author_ip .. "," .. "NOW()" .. "," | |
.. "UTC_TIMESTAMP()" .. "," .. quoted_comment_content .. "," | |
.. quoted_comment_karma .. "," .. quoted_comment_approved .. "," | |
.. quoted_comment_agent .. "," .. quoted_comment_type .. "," | |
.. quoted_comment_parent .. "," .. quoted_user_id .. ")" | |
-- ngx.say(query) | |
res, err, errno, sqlstate = | |
db:query(query) | |
if not res then | |
ngx.say("bad result: ", err, ": ", errno, ": ", sqlstate, ".") | |
return | |
end | |
local ok, err = db:set_keepalive(300000, 100) | |
if not ok then | |
-- ngx.say("failed to set keepalive: ", err) | |
return | |
end | |
local memcached = require "resty.memcached" | |
local client, err = memcached:new() | |
client:connect("127.0.0.1", 11211) | |
if not client then | |
ngx.say("failed to instantiate memc: ", err) | |
return | |
end | |
local i = args["comment_post_ID"] | |
local val, flags, err = client:incr(i, 1) | |
--ngx.say("Value is: ", val) | |
ngx.location.capture("/sleep") | |
local location = "http://" .. ngx.var.http_host .. "/?p=" .. args["comment_post_ID"] .. "#comment-" .. val | |
ngx.header.Location = location | |
'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment