Skip to content

Instantly share code, notes, and snippets.

@developersteve
Created September 2, 2018 22:44
Show Gist options
  • Save developersteve/17203742744b2c1b5c4059d36c31e281 to your computer and use it in GitHub Desktop.
Save developersteve/17203742744b2c1b5c4059d36c31e281 to your computer and use it in GitHub Desktop.
Nginx notifyURL to slack channel for debugging
server
{
listen 443 http2 ssl;
listen [::]:443 http2 ssl;
server_name [domain url in here];
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
proxy_cookie_domain ~(?P<secure_domain>([-0-9a-z]+\.)?[-0-9a-z]+\.[a-z]+)$ "$secure_domain; secure";
ssl_protocols TLSv1.2 TLSv1.1 TLSv1 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:!aNULL:!MD5:!DSS;
ssl_ecdh_curve secp384r1;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
ssl_certificate [SSL path here];
ssl_certificate_key [SSL path here];
proxy_redirect off;
location / {
access_by_lua '
local cjson = require "cjson"
ngx.req.read_body()
local head = ngx.req.get_headers()
local post = cjson.decode(ngx.req.get_body_data())
local dt = os.time(os.date("!*t"))
local msg = ""
local header = ""
for k, v in pairs(post) do
msg = msg..k.." > "..v.."\\\n"
end
for k, v in pairs(head) do
header = header..k.." > "..v.."\\\n"
end
local _postc = {}
_postc["text"] = "*POST Body* \\\n \\\n"..msg.."\\\n \\\n*POST Header* \\\n \\\n"..header
_postc["ts"] = dt
_postc["color"] = "#36a64f"
_postc["title"] = "API Debugging"
local outs = {}
outs["attachments"] = {_postc}
ngx.req.set_body_data(cjson.encode(outs))
';
proxy_pass_request_headers off;
proxy_pass_request_body off;
proxy_pass [slack webhook url in here];
proxy_method POST;
proxy_set_body $request_body;
}
@developersteve
Copy link
Author

Requires LUA to be enabled within Nginx

Set up incoming webhooks app on https://api.slack.com/apps and drop the url into [slack webhook url in here]

add a dash of SSL path and the listening domain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment