forked from the-hidden-eye/docker-caching-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
139 lines (123 loc) · 4.55 KB
/
Copy pathnginx.conf
File metadata and controls
139 lines (123 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
user nginx;
worker_processes 1;
error_log /dev/stderr warn;
pid /var/run/nginx.pid;
#include /etc/nginx/modules/http_redis2.conf;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
##resolver 4.2.2.4 8.8.8.8 1.1.1.1 9.9.9.9 ipv6=off valid=90m;
resolver 127.0.0.1 ipv6=off valid=90m;
log_format main '$remote_addr - $remote_user [$time_local] ( $proxy_host $upstream_http_host $upstream_addr $upstream_response_time msec $msec request_time $request_time) "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
proxy_force_ranges on;
proxy_cache_path /cache levels=1:2 keys_zone=my_cache:10m max_size=1g
inactive=$MAX_INACTIVE use_temp_path=off;
map $sent_http_content_type $cacheable_types {
"image/gif" "max-age=864000";
"image/jpeg" "max-age=864000";
~image/ 10d;
default "";
}
map $sent_http_content_type $expires {
default off;
application/pdf 1h;
~image/ 10d;
}
upstream getbackend {
keepalive 100;
server MYUPSTREAM:MYPORT max_fails=2 fail_timeout=5s;
#more_backends
}
upstream redisbackend {
server 127.0.0.1:6379;
# a pool with at most 1024 connections
# and do not distinguish the servers:
keepalive 1024;
}
proxy_ssl_verify off;
proxy_ssl_server_name on;
proxy_ssl_name $upstream_addr;
proxy_set_header Host $proxy_host;
server {
resolver 127.0.0.1 ipv6=off valid=90m;
listen 80;
access_log /dev/stdout main;
location /healthcheck {
access_log /dev/null;
default_type text/plain;
return 200 '200 OK == alive';
# because default content-type is application/octet-stream,browser will offer to "save the file"... if you want to see reply in browser, uncomment next line
add_header Content-Type text/plain;
}
location /favicon.ico {
return 301 "https://github.com/favicon.ico";
}
#location / {
#set $redis_key $uri;
#
# redis_pass redisbackend;
##redis2_pass redisbackend;
#default_type text/html;
#error_page 404 = /catchme;
#}
location / {
proxy_connect_timeout 42;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;
# Remove the Connection header if the client sends it,
# it could be "close" to close a keepalive connection
proxy_set_header Connection "";
#resolver 127.0.0.11 valid=10s;
#set $backend MYUPSTREAM;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
#proxy_ssl_name $proxy_host;
proxy_ssl_session_reuse on;
proxy_hide_header X-Accel-Expires;
proxy_hide_header Expires;
proxy_hide_header Cache-Control;
proxy_hide_header Pragma;
proxy_hide_header Host;
add_header Host $http_host;
add_header "Cache-Control" $cacheable_types;
#add_header "Expires" $expires;
expires $expires;
etag off;
if_modified_since off;
#proxy_redirect $backend /
#proxy_pass $backend;
# set $empty "";
# proxy_pass UPSTREAM_PROTO://backend$empty;
proxy_pass http://getbackend;
#proxy_redirect default;
#if ($upstream_status = 401) {
#
# }
proxy_cache my_cache;
proxy_read_timeout 10s;
# Enable caching with Redis
proxy_cache_revalidate on;
proxy_cache_lock on;
###proxy_cache_use_stale updating;
###proxy_cache_background_update on;
###proxy_cache_key "$scheme$request_method$host$request_uri";
###proxy_cache_bypass $http_upgrade;
###proxy_cache_valid any 5m;
###proxy_cache redis_cache;
###proxy_cache_redis unix:/var/run/redis/redis.sock;
$PROXY_CACHE_VALID
add_header 'Access-Control-Allow-Origin' '$ALLOWED_ORIGIN';
}
}
}