Skip to content

Instantly share code, notes, and snippets.

@LittleFox94
Forked from regadas/nginx.conf
Created June 11, 2020 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LittleFox94/c29775fc749aff914029ac5a8c48276c to your computer and use it in GitHub Desktop.
Save LittleFox94/c29775fc749aff914029ac5a8c48276c to your computer and use it in GitHub Desktop.
nginx cached forward proxy #example
user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
##
# Proxy
##
proxy_buffering on;
proxy_cache_path /var/cache/proxy-nginx levels=1:2 keys_zone=proxy-cache:10m max_size=3g inactive=1d;
proxy_temp_path /var/cache/proxy-nginx/tmp;
proxy_buffer_size 4k;
proxy_buffers 256 4k;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format cache_status '[$time_local] "$request" $upstream_cache_status';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/cache_access.log cache_status;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
server {
resolver 8.8.8.8;
listen [::]:8080;
location / {
expires max;
proxy_cache proxy-cache;
proxy_cache_valid 200 302 301 1h;
proxy_cache_valid any 1m;
proxy_cache_key "$scheme://$host$request_uri";
proxy_pass $scheme://$host$request_uri;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_ignore_headers "Set-Cookie";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment