Something Strange

Igor Sysoev is at rambler-co.ru
Wed Jan 28 17:51:39 MSK 2009


On Mon, Jan 26, 2009 at 04:30:43PM -0500, Shamunda wrote:

> Hello All -
>  
> I'm having a very strange issue and maybe someone has experienced it or knows the solutions.
>  
> I'll try to be brief.  I have two clusters; we'll call them cluster 1 & 2.
>  
> When I run the configuration everything appears to work.
>  
> But the strange this is that it will only work if I use the URL and not the IP.   If i use the IP address it defaults to the other cluster...very strange...here's my config to get a better picture.
>  
> user       www-data;
> worker_processes  2;
> # pid of nginx master process
> pid /var/run/nginx.pid;
> # uknown directive
> #worker_rlimit_nofile 8192;
> events {
>     worker_connections  4096;
>     # use epoll;
> }
> http {
>     # Allow long server names
>     server_names_hash_bucket_size 128; 
>     include    /etc/nginx/mime.types;
>     default_type application/octet-stream;
>     
>     log_format   main '$remote_addr - $remote_user [$time_local] $status '
>                       '"$request" $body_bytes_sent "$http_referer" '
>                       '"$http_user_agent" "$http_x_forwarded_for"';
>     # main log files
>     access_log   /var/log/nginx/access.log  main;
>     error_log  /var/log/nginx_error.log debug;
>     # spool uploads to disk instead of clobbering downstream servers
>     # client_body_temp_path /var/spool/nginx-client-body 1 2;
>     # client_max_body_size 32m;
>     # client_body_buffer_size    128k;
>     
>     server_tokens       off;
>     keepalive_timeout   5;
> 
>     
>     # no sendfile on OSX
>     sendfile     on;
>     # Optimized default values
>     tcp_nopush   on;
>     tcp_nodelay  off;
>     
>     # compression saves bandwidth
>     gzip               on;
>     gzip_http_version 1.0;
>     gzip_comp_level     2;
>     gzip_proxied      any;
>     gzip_min_length  1100;
>     gzip_buffers  16 8k;
>     gzip_types      text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
>     gzip_disable "MSIE [1-6].(?!.*SV1)";
>     gzip_vary on;
>     # proxy settings
>     proxy_redirect     off;
>     proxy_set_header   Host             $host;
>     proxy_set_header   X-Real-IP        $remote_addr;
>     proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
>     proxy_max_temp_file_size 0;
>     proxy_connect_timeout      90;
>     proxy_send_timeout         90;
>     proxy_read_timeout         90;
>     proxy_buffer_size          4k;
>     proxy_buffers              4 32k;
>     proxy_busy_buffers_size    64k;
>     proxy_temp_file_write_size 64k;
>  
>     upstream cluster1 {
>     ip_hash;
>            server 10.100.50.72:80;
>            server 10.100.50.78:80;
>            }
>     include    /etc/nginx/cluster1/cluster1.conf;
>  
>     upstream cluster2 {
>     ip_hash;
>            server 10.100.50.73:80;
>            server 10.100.50.79:80;
>            }
>     include    /etc/nginx/cluster2/cluster2.conf;
> }
>  
>  
> Here are my two includes:
>  
> server {
>         listen 80;
>         server_name 10.100.50.13 cluster1.nowhere.net;
>         access_log  /var/log/nginx/cluster1.access.log main;
>         location / {
>                     proxy_pass   http://cluster1;
>                     proxy_set_header    Host    $host;
>                     proxy_set_header    X-Real-IP       $remote_addr;
>                     proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
>                    }
>         error_page   500 502 503 504  /50x.html;
>         location = /50x.html {
>                               root   /var/www/nginx-default;
>                              }
>        }
>  
> server {
>         listen 80;
>         server_name 10.100.50.14 cluster2.nowhere.net;
>         access_log  /var/log/nginx/cluster2.access.log main;
>         location / {
>                     proxy_pass   http://cluster2;
>                     proxy_set_header    Host    $host;
>                     proxy_set_header    X-Real-IP       $remote_addr;
>                     proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
>                    }
>         error_page   500 502 503 504  /50x.html;
>         location = /50x.html {
>                               root   /var/www/nginx-default;
>                              }
>        }
>  
> So in the 'include' files you'll notice i have the URL's.  If keep the URL's in the configuration everythign works fine.
> However if I just want to use the IP it defaults to the first conf  file
>  
> Example:  server_name 10.100.50.14;   
>  
> Will always mysteriously just default to 10.100.50.13... 
>  
> Any help would be appreciated.

server_name is used to test "Host" header.
The IP address will be in the header only if you enter
http://10.100.50.14/ in browser.

You need something like:

    server {
         listen       10.100.50.14:80;
         server_name  cluster2.nowhere.net;


http://wiki.codemongers.com/NginxHttpCoreModule#listen
http://wiki.codemongers.com/NginxHttpCoreModule#server_name


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list