0

I developed on an apache, now I need to deploy on ngix and I ran into some difficulties. Because inline-styles are disabled in my project (with cakephp) and there are some colours defined in the database, I made the RsrcController generating the css with the colours into a template.

Calling this function works only if I don't use the file extension .css, but just the slashed Url with controller and function.

If I append the file ending .css, nginx is searching in the webroot folder and returns a 404.

This is the relevant part of the config:

        location / {
            try_files $uri $uri/ /index.php?$args;
        }


        #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
           try_files $uri =404;
           include /etc/nginx/fastcgi_params;
           fastcgi_pass    127.0.0.1:9000;
           fastcgi_index   index.php;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

I tried to find a solution adding another location rule like this:

location ~ rsrc/css_vars/~.css {
    ... [->second part of my question]
}

I dont want to pass all .css files to php. just those i expect to be dynamic generated. Anyhow, my changes dont seem to work.

Second part:

Cakephp works following way: http://url.com/controller/function/var1/var2/varx My contoller is rsrc. My function is css_vars. Than there are some vars (user...) and at the end I need the ".css".

I thought of rewriting the URl to the same but without the file extension ".css". Is there any way to come around regular expressions?

0

I implemented following solution:

#special for rsrc controller
location ~ ^/rsrc/css_vars/.*\.css$ {
   rewrite "^(.+)\.\w+$" "$1" last;
}

This is going to cut away .css from the request if the request is for rsrc controller and function css_vars.

0

You can also do it like this:

location ~ ^(/rsrc/css_vars/.+)\.css$ {
    rewrite ^ "$1" last;
}

It is a bit more efficient, since we trigger the regex engine only once, and capture the needed part in the location directive. I also changed this to not match /rsrc/css_vars/.css path, since the * version would have matched it also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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