Welcome! Log In Create A New Profile

Advanced

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

October 31, 2009 06:48PM
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 :

[code]
<FilesMatch "(?i)^.*\.(css)$">
SetHandler application/x-httpd-php
</FilesMatch>
[/code]

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 : http://www.mydomain.com/somefile.php), I get a download prompt.

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

[code]

server
{
listen [my_ip]:80 default;
server_name mydomain.com www.mydomain.com;
expires 0;

access_log access.log;
error_log error.log;

# Redirect from non-www to www
if ($host = 'mydomain.com')
{
rewrite ^/(.*)$ http://www.mydomain.com/$1 permanent;
}

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

location /
{

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

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

# if directory exists return it right away
if (-d $request_filename)
{
break;
}

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

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

# set document root
root [docroot];

# fastcgi setup
fastcgi_pass 127.0.0.1:9000;
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;
}

}


[/code]
Subject Author Posted

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

ftrudeau October 31, 2009 06:48PM

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

ftrudeau November 01, 2009 01:26PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 310
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready