worker_processes 4; # , # cat /proc/cpuinfo | grep processor | wc - http { resolver 127.0.0.1; # . reverse proxy. 127.0.0.1 DNS . , , . resolver . DNS ! include options.conf; include mime.types; # , , -, iso-8859-1. - , , UTF-8. charset utf-8; override_charset on; source_charset iso-8859-1; charset_map iso-8859-1 utf-8 { } # charset_map - , ! charset_map iso-8859-1 _ { } . # . ? ! proxy_cache_path /usr/local/nginx/proxy_temp/ levels=1:2 keys_zone=cache-zone:10m inactive=10m max_size=1000M; # proxy_store_access user:rw group:rw all:r; # proxy_cahe proxy_store , . . # … include example.conf; }
server { listen 80; server_name example.ru; access_log logs/example.ru.access.log main; error_log logs/example.ru.error.log; index index.html; root /usr/local/nginx/html/example.ru; # : rewrite ^/(/broken_page.*) http://www.example.com/$1 permanent; # “” , Nginx reverse-proxy. , , 404. . Nginx Pop-up . # ! # /img/ URI . . location ^~ /img/ { # ? , ! root /usr/local/nginx/html/example.ru; # ! try_files $uri $uri/ @static; } # , , , , @static, . () , , , . , -. # : location @static { proxy_pass http://super-cdn.com$uri; # , 1-2 . : http://super-cdn.com/img proxy_store /usr/local/nginx/html/${uri}; expires max; # expires max - , . . , . ( , ) nginx -s reload. firebug . Nginx. # ! access_log logs/2.access.log; error_log logs/2.error.log debug; } # . location / { include example-transform.conf; # proxy_pass http://www.example.com; # proxy_redirect off; proxy_cache cache-zone; # ? proxy_cache_min_uses 2; proxy_cache_valid 200 1h; # : proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
http://super-cdn.com/img
= http: //super-cdn.com/img/*not proxied. It is clear that this is due to the difference of the domain. It is also clear that in such a situation we have no opportunity to slip the translated pictures, because the user takes them directly from the CDN bypassing us. So the transformation magic is required!
sub_filter 'http://super-cdn.com/img/' 'http://example.ru/img/' ; sub_filter_once off;
./configure --with-http_sub_module
subs_filter 'http://super-cdn.com/img/' 'http://example.ru/img/' g; subs_filter '<title[^>]*>(.*?)</title>' '<title> . !</title>' oir;
: //I leave the block without illumination, so as not to introduce unnecessary errors in the config.
Source: https://habr.com/ru/post/114845/
All Articles