How to use private file system that work with image styles for drupal 7 and 8

Events happening in the community are now at Drupal community events on www.drupal.org.
spacereactor's picture

Spend few days trying to solve this and there is how i get it to work for drupal 7 & 8. If you have better solution for private file system that work with image styles please add in.

I using the standard drupal conf from https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/

======================================
IMPORTANT
Private file system path = sites/default/files/private
if you use other path change according for your setting at location ~ ^/sites/.*/files/private/styles/

======================================
For drupal 8, i need to add the below rewrite inorder to run properly

rewrite ^/core/authorize.php/core/authorize.php(.*)$ /core/authorize.php$1;

======================================
Change the server_name, root, and fastcgi_pass unix
Add this
location ~ ^/sites/.*/files/private/styles/ {
try_files $uri @rewrite;
}

AND change this

location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {

location ~* \.(js|css|ico)$ {
    expires max;
    log_not_found off;
}

======================================
There is a example

server {
server_name my-website-domain-name;
root my-website-domain-name;
access_log off;
error_log off;
client_max_body_size 1000M;
rewrite ^/core/authorize.php/core/authorize.php(.*)$ /core/authorize.php$1;

location = /favicon.ico {
    log_not_found off;
    access_log off;
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

location ~* \.(txt|log)$ {
    allow 192.168.0.0/16;
    deny all;
}

location ~ \..*/.*\.php$ {
    return 403;
}

location ~ ^/sites/.*/private/ {
    return 403;
}

location ~* ^/.well-known/ {
    allow all;
}

location ~ (^|/)\. {
    return 403;
}

location / {
    try_files $uri /index.php?$query_string;
}

location @rewrite {
    rewrite ^/(.*)$ /index.php?q=$1;
}

location ~ /vendor/.*\.php$ {
    deny all;
    return 404;
}

location ~ '\.php$|^/update.php' {
    fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
}

location ~ ^/sites/.*/files/private/styles/ {
    try_files $uri @rewrite;
}

location ~ ^/sites/.*/files/styles/ {
    try_files $uri @rewrite;
}

location ~* \.(js|css|ico)$ {
    expires max;
    log_not_found off;
}
}

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: