Can't get Nginx to work with memcached


#1

Hi,

I think I’m having trouble even getting the most basic case of
Nginx+memcached working properly. Here is my /etc/nginx/nginx.conf file:

user www-data;
worker_processes 1;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

access_log  /var/log/nginx/access.log;

sendfile        on;
tcp_nopush     on;

#keepalive_timeout  0;
tcp_nodelay        on;

gzip  on;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

upstream backend {
server 127.0.0.1:81;
}

server{
listen 80;
location / {
set $memcached_key $uri;
memcached_pass 127.0.0.1:11211;
default_type text/html;
error_page 404 = /fetch;
}

location =/fetch {
  proxy_pass http://backend;
  break;
}

}
}

I have nginx running on localhost:80 and an apache server on
localhost:81. With this setup, when running memcached -vv, I should see
output whenever any HTTP request is sent to the nginx server, because it
should be searching for cached items, right? However I see absolutely no
output from memcached -vv…

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2438,2438#msg-2438


#2

I solved the problem. It was because I didn’t edit my
/etc/nginx/sites-available/default file to include the new information.
So many tutorials didn’t mention that you have to edit this file! =(

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2438,2463#msg-2463


#3

Arrgghh… so, I found out that some things are bugged within
0.6.32 so I installed 0.6.37 from source. After configuring everything,
the same problem is occuring- ie: memcaching does not work. Here are my
configs. Any help is much appreciated.

/usr/local/nginx/conf/nginx.conf

user www-data;
worker_processes 1;

error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] 

$request ’
'"$status" $body_bytes_sent “$http_referer” ’
‘"$http_user_agent" “$http_x_forwarded_for”’;

access_log  logs/access.log  main;

sendfile        on;
tcp_nopush     on;

#keepalive_timeout  0;
#keepalive_timeout  65;

gzip  on;

include /usr/local/nginx/conf/nginx.conf.default;

upstream backend {
server 127.0.0.1:81;
}

server {

    #charset koi8-r;

    #access_log  logs/host.access.log  main;
listen 80;

    location / {
        root   html;
        index  index.html index.htm;
  set $memcached_key    $uri;
  memcached_pass     127.0.0.1:11211;
  default_type     text/html;
  error_page         404 = /fetch;
    }

location /fetch {
  proxy_pass http://backend;
  break;
}

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

}

/usr/local/nginx/conf/nginx.conf.default

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
    root   html;
    index  index.html index.htm;
set $memcached_key    $uri;
memcached_pass     127.0.0.1:11211;
default_type     text/html;
error_page         404 = /fetch;
}

location /fetch {
proxy_pass http://backend;
break;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}

}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2438,2468#msg-2468


#4

Funny my freebsd config has that feature too ;). [however, I symlink to
a
conf.d instead of sites-enabled]

It’s really the maintainer’s fault - I don’t know why he decided to copy
the
apache configuration but then didn’t provide enable/disable scripts.
One
day I’m going to hunt this guy down (onlines!) and let him know he is
making
so much trouble on our list when we all wanted to get away from apache
for
the most part anyway :P.

– Merlin


#5

On Thu, 2009-05-28 at 14:00 -0400, sayeo87 wrote:

I solved the problem. It was because I didn’t edit
my /etc/nginx/sites-available/default file to include the new
information. So many tutorials didn’t mention that you have to edit
this file! =(

That’s because sites-available/* is a Debian-only “feature”.

Cliff