Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

Drupal 7 does not generate styles using clean urls on Ubuntu 16.04 NGINX/PHP-FPM

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
2 posts • Page 1 of 1
7thkey
Posts: 8
Joined: Wed Aug 06, 2014 4:49 pm

Drupal 7 does not generate styles using clean urls on Ubuntu 16.04 NGINX/PHP-FPM
  • Quote

Post by 7thkey » Wed Apr 05, 2017 10:59 am

I cannot get it to work, i have a fresh Vesta installation on Ubuntu 16.04 and NGINX + php-fpm web server.
Created a web with nginx template "drupal 7" and backend template "default".

Install a fresh Drupal 7, add an article with an image and view the recently created article. The browser returns error 404 not found image. Drupal does not log any errors nor does nginx logs.

I've tried to change folder permissions and the problem persists.

I've tried to change nginx.conf
from

Code: Select all

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

Code: Select all

    location ~* /sites/.*/files/styles/ {
            access_log off;
            expires 30d;
            try_files $uri @rewrite;
    }
reload the configuration and restarted the server and the problem persist.

Edited:
Drupal 7 without Clean URL works and I can confirm that has nothing to do with folder permissions.

Anyone has the same issue?
Top

7thkey
Posts: 8
Joined: Wed Aug 06, 2014 4:49 pm

Re: Drupal 7 does not generate styles using clean urls on Ubuntu 16.04 NGINX/PHP-FPM
  • Quote

Post by 7thkey » Wed Apr 05, 2017 12:57 pm

I found the solution and works, this needs to be updated into Vesta nginx templates!!

Based on NGINX https://www.nginx.com/resources/wiki/st ... es/drupal/ updated Drupal recipes i've adapted the Drupal 7 NGINX template as follows:

Code: Select all

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

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

    # Very rarely should these ever be accessed outside of your lan
    location ~* \.(txt|log)$ {
        allow 192.168.0.0/16;
        deny all;
    }

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

    # No no for private
    location ~ ^/sites/.*/private/ {
        return 403;
    }

    # Allow "Well-Known URIs" as per RFC 5785
    location ~* ^/.well-known/ {
        allow all;
    }

    # Block access to "hidden" files and directories whose names begin with a
    # period. This includes directories used by version control systems such
    # as Subversion or Git to store control files.
    location ~ (^|/)\. {
        return 403;
    }

    location / {
        # try_files $uri @rewrite; # For Drupal <= 6
        try_files $uri /index.php?$query_string; # For Drupal >= 7
    }

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

    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }

    location ~ [^/]\.php(/|$) {
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        if (!-f $document_root$fastcgi_script_name) {
            return  404;
        }

        fastcgi_pass    127.0.0.1:9002;
        fastcgi_index   index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_intercept_errors on;
        include         /etc/nginx/fastcgi_params;
    }

    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

    # Handle private files through Drupal. Private file's path can come
    # with a language prefix.
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
Top


Post Reply
  • Print view

2 posts • Page 1 of 1

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password