Skip to content

Instantly share code, notes, and snippets.

@mariotristan
Created November 2, 2022 23:30
Show Gist options
  • Select an option

  • Save mariotristan/f21d010e759065c3244d9183763a5cd7 to your computer and use it in GitHub Desktop.

Select an option

Save mariotristan/f21d010e759065c3244d9183763a5cd7 to your computer and use it in GitHub Desktop.
Nginx conf to customize log format and include request-body with no escape
events {
worker_connections 768;
}
http {
# Nginx will handle gzip compression of responses from the app server
gzip on;
gzip_proxied any;
gzip_types text/plain application/json;
gzip_min_length 1000;
server_tokens off;
#Define the custom log format we want
log_format custom escape=none '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio" --- '
'"$request_body"';
server {
access_log /var/log/nginx/access.log custom;
location /route1/ {
proxy_pass https://domain1.com/;
}
location /api/ {
proxy_pass https://domain2.com/;
}
location =/ {
if ($request_method !~ ^(GET|POST|HEAD|OPTIONS|PUT|DELETE|PATCH)$) {
return 405;
}
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' $http_origin always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,HEAD,OPTIONS,PUT,DELETE,PATCH';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
proxy_set_header Host dev.digitalmxce.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_bind $server_addr;
proxy_pass https://cooldomain.com;
}
location / {
# handle everything else
return 403;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment