From Apache to Nginx+php-fpm : How to port configuration ?

ftrudeau nginx-forum at
Sun Nov 1 01:48:18 MSK 2009

Greetings all.

I successfully installed nginx + php-fpm. I already read numerous tutorials and exemples out there on the web, and I would need some additional insights on how to port the various configuration options I had via .htaccess under Apache.

For instance, CSS files needs to be processed by PHP.
Under Apache, I simply put this in the .htaccess :

	SetHandler application/x-httpd-php

1) How can I achieve this under Nginx with php-fpm ?
2) Any way to specify per server PHP configs à-la Apache (ex : php_value memory_limit 64M) ?
3) Weird behavior : if I try to access a PHP file (ex :, I get a download prompt.

Here is the server configuration for mydomain.
Any tweaks and advices would be appreciated.

                listen          :80 default;
                expires         0;

                access_log      access.log;
                error_log       error.log;

                # Redirect from non-www to www
                if ($host = '')
                        rewrite  ^/(.*)$$1  permanent;

                # Simple static content delivery system (versionning only)
                location ~* "^(+)-[0-9]{10}\.(js|gif|jpg|jp?g|png|css|swf)$"
                        rewrite "(.*)/(+)-[0-9]{10}\.(js|gif|jp?g|png|css|swf)$" $1/$2.$3 last;
                        return 403;

                location /

                        # set document root and index file
                        root     ;
                        index   index.php index.html index.htm;

                        # if file exists, set expire and return it
                        if (-f $request_filename)
                                expires 1y;

                        # if directory exists return it right away
                        if (-d $request_filename)

                        # rewrite everyting else to index.php
                        if (!-e $request_filename)
                                rewrite  ^  /index.php  last;

                # if the request starts with our frontcontroller, pass it on to fastcgi
                location ~ ^/index.php

                        # set document root
                        root            ;

                        # fastcgi setup
                        fastcgi_index   index.php;
                        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

                        fastcgi_param   QUERY_STRING            $query_string;
                        fastcgi_param   REQUEST_METHOD          $request_method;
                        fastcgi_param   CONTENT_TYPE            $content_type;
                        fastcgi_param   CONTENT_LENGTH          $content_length;

                        fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
                        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;

                        # PHP only, required if PHP was built with --enable-force-cgi-redirect
                        fastcgi_param   REDIRECT_STATUS         200;


                # Prevent files beginning with . from being viewed
                location ~ /\.
                        deny  all;


Posted at Nginx Forum:,18743,18743#msg-18743

More information about the nginx mailing list