Skip to content

Instantly share code, notes, and snippets.

@neoneye
Created September 4, 2016 16:44
Show Gist options
  • Save neoneye/fe0091c773edc28afd0db8580f8be8fe to your computer and use it in GitHub Desktop.
Save neoneye/fe0091c773edc28afd0db8580f8be8fe to your computer and use it in GitHub Desktop.
NGINX controls a FastCGI script
user neoneye staff;
worker_processes 1;
error_log /Library/Logs/nginx/error.log debug;
events {
worker_connections 256;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /Library/Logs/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 12345;
server_name localhost;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
fastcgi_pass localhost:8000;
include fastcgi_params;
}
location /static/ {
alias /Users/neoneye/git/GraphToy/server_static_files/;
autoindex on;
}
location /upload {
limit_except POST { deny all; }
# Size of File Uploads. "Request entity too Large" (413) is a common error message,
# when the user is trying to upload a file that is too big.
client_max_body_size 100M;
# Pass altered request body to this location
upload_pass @test;
# Store files to this directory
upload_store /tmp/graphtoy_upload_store;
# Allow uploaded files to be read only by user
upload_store_access user:rw group:rw all:rw;
# Set specified fields in request body
upload_set_form_field "${upload_field_name}_name" $upload_file_name;
upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;
# Inform backend about hash and size of a file
upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;
# pass all other fields posted to the backend
upload_pass_form_field "^(.*)$";
}
# Pass altered request body to a backend
location @test {
fastcgi_pass localhost:8000;
include fastcgi_params;
proxy_buffer_size 256k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 512k;
fastcgi_buffers 8 256k;
fastcgi_buffer_size 128k;
}
location @uploaded {
# rewrite ^ /data/uploaded last;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment