Nginx memcached setting
Jim Ohlstein
jim at ohlste.in
Tue Nov 23 01:58:25 MSK 2010
On 11/21/10 12:29 PM, sastro wrote:
> My server running Nginx and php-fpm for wordpress. Today i installed
> memcached but i dont know how to setting the memcached thing into conf
> file. Here is my wordpres conf file
> [code]
> server{
> listen 80;
> server_name www.mywebsite.com;
> access_log /var/log/nginx/mywpt.access_log;
> error_log /var/log/nginx/mywpt.error_log;
>
> root /home/mywebsite/public_html;
>
> location / {
> root /home/mywebsite/public_html/;
> index index.html index.htm index.php;
>
> # this serves static files that exist without running other
> rewrite tests
> if (-f $request_filename) {
> expires 30d;
> break;
> }
>
> # this sends all non-existing file or directory requests to
> index.php
> if (!-e $request_filename) {
> rewrite ^(.+)$ /index.php?q=$1 last;
> }
> }
>
> location ~ \.php$ {
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME
> /home/mywebsite/public_html/$fastcgi_script_name;
> include fastcgi_params;
> }
>
> }
>
> [/code]
>
>
> where to put this code ?
>
> server {
> location / {
> set $memcached_key $uri;
> memcached_pass name:11211;
> default_type text/html;
> error_page 404 @fallback;
> }
>
> location @fallback {
> proxy_pass backend;
> }
> }
Nowhere. Use the WordPress memcached plugin at
http://wordpress.org/extend/plugins/memcached/ and it will do the work
for you. Do make certain that you have memcached installed (and running)
as well as the PECL-memcache PHP extension. See http://memcached.org/
and http://pecl.php.net/package/memcache.
BTW, if you really want efficiency for your site, and since you're
asking about using memcached it seems that you are, you should rewrite
the config to get rid of the if's, and use locations and try_files
instead. See http://wiki.nginx.org/IfIsEvil.
A more efficient config might be (not tested so YMMV):
server{
listen 80;
server_name www.mywebsite.com;
access_log /var/log/nginx/mywpt.access_log;
error_log /var/log/nginx/mywpt.error_log;
root /home/mywebsite/public_html;
#will capture most static files and serve them. Add other types if you
need to
location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ {
expires 30d;
}
location / {
root /home/mywebsite/public_html/;
index index.html index.htm index.php;
# this will capture and serve any other static file types
missed above and send the rest to your fallback rewrite
try_files $uri $uri/ /index.php?q=$request_uri;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/home/mywebsite/public_html/$fastcgi_script_name;
include fastcgi_params;
}
}
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,152247,152247#msg-152247
--
Jim Ohlstein
>> Why?
> Because it breaks the logical flow of conversation, plus makes
messages unreadable.
>>> Top-Posting is evil.
More information about the nginx
mailing list