I deep dive in the settings.php file of Drupal 8.1 and try to configure $settings['file_public_base_url']and $settings['file_public_path'].

All media links are correctly rewritten, that works with static files, but styles fails with 404 errors as there is no php support and rewriting rules are not implemented.

How can you get styles to work with $settings['file_public_base_url'] ? Is it related with Image cache external ?


Finally got it working. It seems that currently there is a bug in the image core module that prevents the use of absolute paths in the $settings['file_public_path'].

For those interested, you can follow the issue where you can find the patch attached.

Note, that you must also set some rewrite rules on your static files server to get it working. I provided a docker example on how to configure this on GitHub, but mainly here are the main config:

Vhost configuration of the static file server

Configuration example provided for Nginx:

server {
    listen 80  default_server;
    root /files/domain.fr/public;

    index index.html index.htm;

    location @rewrite {
        rewrite ^/(.*)$ http://DRUPAL.SERVER.IP/files/domain.fr/public/$1;

    location ~ ^/styles {
       try_files $uri @rewrite;

    location ~ ^/core {
        rewrite ^/(.*)$ http://DRUPAL.SERVER.IP/$1;

Drupal settings file

Add this to your settings.php file:

$settings['file_public_base_url'] = 'http://STATIC.WEB.SERVER';
$settings['file_public_path'] = '/files/domain.fr/public';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.