Proxy and cache external resource with nginx

proxy_cache_path /home/nginx levels=1:2 keys_zone=CACHE:50m max_size=12G inactive=30d;

server {
	server_name example.com;

	location / {
		proxy_cache_key "$uri";
		proxy_pass https://$path$is_args$args;
		resolver 8.8.8.8;
		proxy_cache            CACHE;
		access_log      off;
		expires max;
		add_header X-Proxy-Cache $upstream_cache_status;
		proxy_set_header Referer "";
		proxy_cache_valid 200 30d;
		proxy_cache_valid 403 10m;
		proxy_cache_valid 404 10m;
		
		proxy_ssl_server_name on;
                proxy_ssl_name $proxy_host;
	}

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
15 декабря 2023, 12:59

CORS in nginx

if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin";
			add_header 'Access-Control-Allow-Credentials' 'true';
			add_header 'Access-Control-Allow-Methods' 'GET, POST,PUT,DELETE,OPTIONS';
			add_header 'Access-Control-Allow-Headers' 'Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Origin,Accept';
			add_header 'Content-Type' 'application/json';
			add_header 'Content-Length' 0;
 
			return 204;
		}
31 января 2017, 13:28

Nginx websocket configuration

location /chat {
proxy_pass http://node_app; 
proxy_http_version 1.1; 
proxy_set_header Upgrade $http_upgrade; 
proxy_set_header Connection "upgrade";
}
27 июля 2015, 02:00

Установка nginx в ubuntu 14.04

sudo apt-get install nginx-extras
sudo update-rc.d nginx enable
12 апреля 2015, 11:56