http {
proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=one:16m inactive=7d max_size=1024m;
proxy_temp_path /var/cache/nginx/temp; # http , .
server {
listen 127.0.0.1:80;
server_name example.com www.example.com;
proxy_temp_path /var/cache/nginx/example.com;
location @nocached {
proxy_pass 127.0.0.1:8080;
proxy_redirect example.com:8080/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
proxy_pass 127.0.0.1:8080;
proxy_redirect example.com:8080/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
#
if ($cookie_dle_user_id) { return 412; }
if ($cookie_dle_password) { return 412; }
if ($request_method = POST ) {
return 412;
}
error_page 412 = @nocached;
proxy_cache one;
proxy_cache_key "$request_method|$is_args|$host|$request_uri";
proxy_hide_header "Set-Cookie";
proxy_ignore_headers "Cache-Control" "Expires";
proxy_cache_valid 200 302 304 5m;
proxy_cache_valid 301 1h;
proxy_cache_valid 503 4s;
proxy_cache_valid any 1m;
proxy_cache_use_stale http_502 http_503 http_504;
}
location ~ (admin.php|index.php?action=logout) {
proxy_pass 127.0.0.1:8080;
proxy_redirect example.com:8080/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
location ~* ^.+\.(jpg|jpeg|gif|png|svg|htm|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar)$ {
root /var/www/example/data/www/example.com;
expires 1y;
access_log /var/www/httpd-logs/example.com.access.log;
error_page 404 = @fallback;
}
location @fallback {
proxy_pass 127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
Source: https://habr.com/ru/post/79876/