404 with serving static files in a custom nginx configuration

Posted by code90 on Server Fault See other posts from Server Fault or by code90
Published on 2012-09-07T08:54:27Z Indexed on 2012/09/07 9:39 UTC
Read the original article Hit count: 229

Filed under:

In my nginx configuration, I have the following:

location /admin/ {
  alias /usr/share/php/wtlib_4/apps/admin/;

  location ~* .*\.php$ {
    try_files $uri $uri/ @php_admin;
  }

  location ~* \.(js|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air)$ {
    expires 7d;
    access_log off;
  }
}


  location ~ ^/admin/modules/([^/]+)(.*\.(html|js|json|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air))$ {
    alias /usr/share/php/wtlib_4/modules/$1/admin/$2;
  }

  location ~ ^/admin/modules/([^/]+)(.*)$ {
    try_files $uri @php_admin_modules;
  }

location @php_admin {
    if ($fastcgi_script_name ~ /admin(/.*\.php)$) {
        set $valid_fastcgi_script_name $1;
    }
    fastcgi_pass $byr_pass;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /usr/share/php/wtlib_4/apps/admin$valid_fastcgi_script_name;
    fastcgi_param REDIRECT_STATUS 200;
    include /etc/nginx/fastcgi_params;
}

location @php_admin_modules {
    if ($fastcgi_script_name ~ /admin/modules/([^/]+)(.*)$) {
        set $byr_module $1;
        set $byr_rest $2;
    }
    fastcgi_pass $byr_pass;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /usr/share/php/wtlib_4/modules/$byr_module/admin$byr_rest;
    fastcgi_param REDIRECT_STATUS 200;
    include /etc/nginx/fastcgi_params;
}

Following is the requested url which ends up with "404":

http://www.{domainname}.com/admin/modules/cms/styles/cms.css

Following is the error log:

[error] 19551#0: *28 open() "/usr/share/php/wtlib_4/apps/admin/modules/cms/styles/cms.css" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: {domainname}.com, request: "GET /admin/modules/cms/styles/cms.css HTTP/1.1", host: "www.{domainname}.com"

Following urls works fine:

http://www.{domainname}.com/admin/modules/store/?a=manage
http://www.{domainname}.com/admin/modules/cms/?a=cms.load

Can anyone see what the problem could be? Thanks.

PS. I am trying to migrate existing sites from apache to nginx.

© Server Fault or respective owner

Related posts about nginx