4

I have a VPS running CentOS with NGINX/PHP-FPM. Everything works fine, except when I add the following lines to enable the static cache content. If I do, the page does not load those files specified to keep cache.

   location ~* \.(ico|css|js|gif|jpg|jpeg|png)$ {
        expires 30d;
        add_header Vary Accept-Encoding;
        access_log off;
   }

This is my entire server{}:

server {
    listen        80;
    server_name  mywebsite.com www.mywebsite.com;

   #location ~* \.(ico|css|js|gif|jpg|jpeg|png)$ {
   #     expires 30d;
   #     add_header Vary Accept-Encoding;
   #     access_log off;
   #}

    location / {
        if ($http_host ~* "^www.(.*)$"){
            set $rule_0 1$rule_0;
            set $bref_1 $1;
        }
        if ($rule_0 = "1"){
           rewrite ^/(.*)$ http://$bref_1/$1 permanent;
        }
        rewrite ^/search/(.*)/(.*)/?$ /index.php?search=$1&page=$2&type=mp3 las$
        rewrite ^/(.*)/(.*)/(.*)?$ /index.php?search=$1&page=$2&type=$3 last;
        root   /var/www/mywebsite.com/public_html;
        index  index.php index.html index.htm;
    }

    location ~ \.php$ {
        fastcgi_read_timeout 300;
        root           /var/www/mywebsite.com/public_html;
        fastcgi_pass unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Does anyone know why?

UPDATED (SOLUTION):

As Michael Hampton answered me, the server{} had not a root declared, so I followed the instructions and I added it to the file. Worked fine!

1
  • What happens when you access the .css file in your browser?
    – ceejayoz
    Mar 30, 2015 at 1:34

1 Answer 1

5

Your server block doesn't have a root directive defined. Instead it seems to be in one of your location blocks. This is one of the most common nginx mistakes. Move it under the server block instead.

1
  • Thanks for this information, Michael! it really solved my problem! Mar 30, 2015 at 1:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .