-
Notifications
You must be signed in to change notification settings - Fork 0
/
staticus.conf
89 lines (83 loc) · 3.54 KB
/
staticus.conf
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
###
### WARNING: This is just example config!
### Use the main ansible project.
###
proxy_cache_path /tmp/nginx levels=1:2 keys_zone=static_cache:100m inactive=120m max_size=500M;
proxy_cache_min_uses 1;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_methods GET HEAD;
#proxy_read_timeout 300s;
server {
listen 8080;
server_name staticus.your.project.dev;
# location / {
# location ~* ^.+\.(jpg|jpeg|gif|png|mp3)$ {
location /staticus/((.|\s)*) {
if ($request_method = 'OPTIONS') {
# Allow requests from all hosts!
# WARNING: THIS IS JUST FOR DEBUG! DO NOT DO THIS ON PRODUCTION!
add_header 'Access-Control-Allow-Origin' $http_origin;
# Cookies
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' '*';
# Custom headers and headers various browsers *should* be OK with but aren't
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
#add_header 'Access-Control-Allow-Headers' '*'; # With http basic authorisation this variant will not work
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
# Allow requests from all hosts!
# WARNING: THIS IS JUST FOR DEBUG! DO NOT DO THIS ON PRODUCTION!
add_header 'Access-Control-Allow-Origin' $http_origin;
# Cookies
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' '*';
# Custom headers and headers various browsers *should* be OK with but aren't
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
#add_header 'Access-Control-Allow-Headers' '*'; # With http basic authorisation this variant will not work
add_header 'Access-Control-Max-Age' 1728000;
proxy_cache static_cache;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_valid 200 10m;
#proxy_buffering on;
#proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
proxy_cache_bypass $http_cache_control;
proxy_set_header Host nocache.$host;
add_header Cache-Control "public";
add_header X-Proxy-Cache $upstream_cache_status;
# proxy_pass http://unix:/var/run/nginx.sock;
proxy_pass http://127.0.0.1:8081$1?$args;
}
}
server {
#listen unix:/var/run/nginx.sock;
listen 8081;
server_name nocache.your.project.dev;
access_log off;
#access_log /var/www/fuse/data/fuse.access.log;
error_log /var/log/nginx/fuse.error.log;
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
internal;
}
location ~* ^(.+)/(gif|jpg|png|mp3)/(.+)\.(jpg|jpeg|gif|png|mp3)$ {
internal;
#allow 127.0.0.1;
#deny all;
#root /var/www/staticus/data; will not work, if cached data not inside project root and if data_dir contains absolute path
root /;
set $root $document_root;
#try_files $uri $uri/;
}
location / {
root /var/www/staticus/public;
set $root $document_root;
add_header Cache-Control "public";
include fastcgi_fpm.conf;
}
}