Welcome! Log In Create A New Profile

Advanced

memcached + nginx + php-fpm

Posted by Prosperent 
memcached + nginx + php-fpm
March 09, 2011 01:11PM
Hello everyone! We have been using nginx for a few months now to handle our image serving and processing. Let me run down the basic flow before getting into my config and issues.

A request comes in, we have nginx check to see if the image exists. If it does, we serve it from the filesystem (nice beefy server with a dozen drives in a raid array). If the image doesn't exist, we send the request off to one of a dozen or so upstream servers running php-fpm. They handle the resize, save the image to the filesystem, then nginx serves it. We would like to add one more layer to everything and set these images in memcached so we can serve subsequent requests from memory instead of the filesystem.

Now, the issue is simply adding memcached to our existing config. I come from a long background of apache, so nginx config still kills me sometimes. I figure a visual is the easiest here, so the following is our existing config. If someone could take a look and offer some suggestions, I would really appreciate it.


server {
listen 8080;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
root /home/images;
index /image.php;




location / {
if (!-f $request_filename) {
rewrite ^(.*)$ /image.php?src=$1 last;
break;
}
}

location ~ "\.(gif|jpeg|jpg|png)$" {
if (!-f $request_filename) {
rewrite ^(.*)$ /image.php?src=$1 last;
break;
}

access_log off;
expires 30d;
}

location ~ "\.(php|phtml)$" {
fastcgi_pass php;
fastcgi_index /image.php;
fastcgi_param SCRIPT_FILENAME /home/images$fastcgi_script_name;
include fastcgi_params;
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_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}


## Disable viewing .htaccess & .htpassword
location ~ /\.ht {
deny all;
}
}

upstream php {
server xx.xx.xx.xx:9000;
server xx.xx.xx.xx:9000;
server xx.xx.xx.xx:9000;
server xx.xx.xx.xx:9000;
server xx.xx.xx.xx:9000;
server xx.xx.xx.xx:9000;
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 230
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