0

Drupal 7 constantly reloads the front page when caching for anonymous users is enabled, no matter which caching engine I use.

I use nginx + php7.0-fpm. Current cache backend is Redis. I cannot catch the error.

I have following behaviour: when caching for anonymous users is enabled, the front page loads completely and then refreshes again and again until I disable caching or clean it all both in Drupal admin interface and in redis cli interface. If the cache changed or expired, then series of reloads start once again. Watchdog does not show any error, so as nginx log.

Any hints?

My settings: Nginx vhost:

server {
    listen 80; 
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example.com;

    return 301 https://$host$request_uri;

 }

 server {
    listen 443 ssl;
    listen [::]:443 ssl;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/jobmens.ru/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/jobmens.ru/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

    server_name example.com www.example.com;
    root /var/www/example.com;

    index  index.html index.htm;

    access_log /var/log/nginx/example.com.access.log;

    error_log /var/log/nginx/example.com.error.log;

    include acme;

    ssi on;
    ssi_silent_errors on;

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

    location ~ /sites/.*/private-files/ {
       deny all;
       return 403;
    }

    location ~ /sites/.*/files/styles/ {
       try_files $uri @drupal;
       expires 31d;
       log_not_found off;
    }

    location ~* \.(eot|otf|ttf|woff|woff2)$ {
       try_files $uri =404;
       expires 31d;
       log_not_found off;
       add_header Access-Control-Allow-Origin *;
    }

    location ~* ^(?!/phpmyadmin/).+\.(png|gif|jpg|jpeg|css|js|ico|swf|flw|cgi|bat|pl|dll|exe|asp|eot|woff|ttf|swg|gz)$ {
       try_files $uri =404;
       expires 31d;
       log_not_found off;
    }

    location ~ (?<upload_form_uri>.*)/x-progress-id:(?<upload_id>\d*) {
       rewrite ^ $upload_form_uri?X-Progress-ID=$upload_id;
    }

    location ^~ /progress {
       upload_progress_json_output;
       report_uploads uploads;
    }

    # Dynamic requests goes here.
    location / {
       error_page 404 502 = @drupal;
       try_files $uri @drupal;
       if ($http_host ~* "^www\.(.+)$"){
          rewrite ^(.*)$ https://example.com$request_uri redirect;
       }
    }

    location @drupal {
       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
       fastcgi_index  index.php;
       fastcgi_read_timeout 600;
       fastcgi_param  SCRIPT_FILENAME      $document_root/index.php;
       fastcgi_param  QUERY_STRING         q=$uri&$args;
       fastcgi_param  REQUEST_METHOD       $request_method;
       fastcgi_param  CONTENT_TYPE         $content_type;
       fastcgi_param  CONTENT_LENGTH       $content_length;
       fastcgi_param  REDIRECT_STATUS      200;
       fastcgi_param  SCRIPT_NAME          /index.php;
       fastcgi_param  REQUEST_URI          $request_uri;
       fastcgi_param  DOCUMENT_URI         $document_uri;
       fastcgi_param  DOCUMENT_ROOT        $document_root;
       fastcgi_param  SERVER_PROTOCOL      $server_protocol;
       fastcgi_param  GATEWAY_INTERFACE    CGI/1.1;
       fastcgi_param  SERVER_SOFTWARE      nginx/$nginx_version;
       fastcgi_param  REMOTE_ADDR          $remote_addr;
       fastcgi_param  REMOTE_PORT          $remote_port;
       fastcgi_param  SERVER_ADDR          $server_addr;
       fastcgi_param  SERVER_PORT          $server_port;
       fastcgi_param  SERVER_NAME          $server_name; 
       fastcgi_param  HTTPS                'on';

       fastcgi_buffers 16 32k;
       fastcgi_buffer_size 32k;

       track_uploads uploads 60s;
    }

 }

Nginx conf:

user webserver;
error_log /var/log/nginx/error.log debug;
# access_log /var/log/nginx/access.log
pid /var/run/nginx.pid;
worker_rlimit_nofile 80000;
worker_processes auto;

events {
    worker_connections 2048;
    use epoll;
}

http {
    server_names_hash_bucket_size 64;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    log_format main ‘$remote_addr – $remote_user [$time_local] $status ‘
        ‘«$request» $body_bytes_sent «$http_referer» ‘
        ‘«$http_user_agent» «http_x_forwarded_for»‘;
    access_log /var/log/nginx/access.log main;
    aio threads;

    client_max_body_size 10M;
    client_body_buffer_size 256k;
    upload_progress uploads 1m;

    sendfile on;
    tcp_nopush on;
    server_tokens off;
    keepalive_timeout 300;

    gzip on;
    gzip_static on;
    gzip_vary on;
    gzip_min_length 1100;
    gzip_buffers 64 8k;
    gzip_comp_level 9;
    gzip_http_version 1.1;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript application/atom+xml application/rdf+xml application/x-font-ttf application/x-font-otf application/font-woff application/font-woff2 application/vnd.ms-fontobject;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
}

php7.0-fpm: only username and socket address modified

Drupal 7 settings:

<?php

$databases = array (
  'default' => 
    array (
      'default' => 
         array (
           'database' => 'dbname',
           'username' => 'dbuser',
           'password' => 'dbpass',
           'host' => 'dbhost',
           'port' => '',
           'driver' => 'mysql',
           'prefix' => '',
           'charset' => 'utf8mb4',
           'collation' => 'utf8mb4_general_ci',
         ),
    ), 
);

$update_free_access = FALSE;

$drupal_hash_salt = 'salt';

$base_url = 'https://example.com';  // NO trailing slash!

ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 100);

ini_set('session.gc_maxlifetime', 200000);

ini_set('session.cookie_lifetime', 2000000);

$conf['reverse_proxy'] = TRUE;

$conf['reverse_proxy_addresses'] = array('IPs',);

$conf['404_fast_paths_exclude'] = '/\/(?:styles)|(?:system\/files)\//';
$conf['404_fast_paths'] = '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i';
$conf['404_fast_html'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>';

$conf['redis_client_interface'] = 'PhpRedis'; // Can be "Predis".
$conf['redis_client_host']      = '127.0.0.1';  // Your Redis instance hostname.
$conf['redis_cache_socket']     = '/var/run/redis/redis.sock';
$conf['lock_inc']               = 'sites/all/modules/redis/redis.lock.inc';
$conf['path_inc']               = 'sites/all/modules/redis/redis.path.inc';
$conf['cache_backends'][]       = 'sites/all/modules/redis/redis.autoload.inc';
$conf['cache_default_class']    = 'Redis_Cache';

uname -a:

4.10.0-36-generic #40~16.04.1-Ubuntu SMP Tue Sep 19 15:26:00 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
2
  • What do you mean by "constantly reload"? You mean you get a too many redirects error? Or any path redirects you to the home page? Or every path shows the home page?
    – YPCrumble
    Commented Sep 23, 2017 at 18:59
  • I have following behaviour: when caching for anonimous users is enabled, the front page loads completely and then refreshes again and again until I disable caching or clean it all both in drupa adminl interface and in redis cli interface. If the cache changed or expired, then series of reloads start once again. The watchdog do not show any error, so as nginx log Commented Sep 23, 2017 at 19:11

1 Answer 1

0

Solution found. Suddenly, it was a problem with IPGV&M module. There is no unexpected behaviour after disabling this module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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