Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

Seeing that your request gets sent to PHP, I would assume that the following location block does not match your request, although that is your intention.

location ~ ^/admin/modules/([^/]+).*\.html|js|json|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air))$ {

From the nginx documentation:

there is no syntax for NOT matching a regular expression. Instead, match the target regular expression and assign an empty block, then use location / to match anything else.

What is your intention with the ([^/]+) part in that location block? I think you can achieve what you want by simply removing that part.

location ~ ^/admin/modules/.*\.html|js|json|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air))$ {
share|improve this answer
    
Please refer to "location @php_admin_modules" block and see the two sets. "/admin/modules/store" in this path "store" is the module name and i need to know this in order to appropriately rewrite. PS. I am trying to migrate my existing sites from apache to nginx. –  code90 Sep 7 '12 at 9:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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