Skip to content

Proxy image server with nginx

You can quickly use Nginx as a proxy image server. For your server security, you can use ‘nginx-accesskey’ module.

Configuration example:

server {
     listen a.b.c.d:443 rcvbuf=64000 sndbuf=120000 backlog=4096 ssl http2;
     server_name mydomain.tld www.mydomain.tld;
     keepalive_timeout         60;
     ssl                       on;
     ssl_protocols	       TLSv1.3 TLSv1.2 TLSv1.1 TLSv1;
     ssl_ciphers               'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS:!RC4';
     ssl_prefer_server_ciphers on;
     ssl_session_cache         shared:TLSSL:30m;
     ssl_session_timeout       60m;
     ssl_buffer_size	       4k;
     ssl_certificate           /etc/letsencrypt/live/mydomain.tld/fullchain.pem;
     ssl_certificate_key       /etc/letsencrypt/live/mydomain.tld/privkey.pem;
     ssl_dhparam	       /etc/ssl/certs/dhparam.pem;
     more_set_headers          "X-Secure-Connection: true";
     add_header                Strict-Transport-Security max-age=315360000;

# enables compression of two or more adjacent slashes in a URI into a single slash.
merge_slashes off;

# image proxy to http
location ~ /(?<r>http://.*) {
        # if you have multiple ip addresses configured on your dedicated server and you want to bind a certain IP
        # proxy_bind a.b.c.d;
	resolver 8.8.4.4 8.8.8.8 4.2.2.2 valid=3600s ipv6=off;
        proxy_set_header Referer "";
        proxy_pass $r;
        expires 10y;
   }

# image proxy to https
location ~ /(?<r>https://.*) {
        # if you have multiple ip addresses configured on your dedicated server and you want to bind a certain IP
        # proxy_bind a.b.c.d;
	resolver 8.8.4.4 8.8.8.8 4.2.2.2 valid=3600s ipv6=off;
        proxy_set_header Referer "";
        proxy_pass $r;
	expires 10y;
   }
 }

How can I use? That’s simple!

https://yourdomainname.tld/http(s)://remotedomain.tld/imagepath/imagename.ext
Published inLinuxWebservers
© 2019 - Marian Amza. All rights reserved.
Powered by Wordpress & Debian