# NGINX login problem

**URL:** <https://www.ruby-forum.com/t/nginx-login-problem/185689>\
**Category:** Rails\
**Created:** [March 24, 2010, 5:51pm UTC](https://www.ruby-forum.com/t/nginx-login-problem/185689 "2010-03-24T17:51:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chuck\_Kyberian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ba9def/32.png) [@Chuck\_Kyberian](https://www.ruby-forum.com/u/Chuck_Kyberian)\
**Post date:** [March 24, 2010, 5:51pm UTC](https://www.ruby-forum.com/t/nginx-login-problem/185689/1 "2010-03-24T17:51:13Z")

</div>

Hi,  
I have a problem with login to my application.  
I use nginx as load-balancer and mongrel cluster as application  
servers. I have 2 servers and 8 mongrels per server.  
When I try to login directly on mongrel, everything is ok. But if I  
use to login nginx, login sometimes failed - login and password are  
nil in admin\_controller and authentication failed in this case.

Do you have some idea to find solution of my problem?  
Thanks…  
Chuck

nginx.conf :

#user and group to run as  
user yeti yeti;

worker\_processes 4;

pid /var/run/nginx.pid;

events {  
worker\_connections 8192;  
use epoll; # linux only!  
}

http {  
include /usr/local/nginx/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 /var/log/nginx/access.log main;

error\_log /var/log/nginx/error.log notice;

sendfile on;

tcp\_nopush on;  
tcp\_nodelay on;

client\_body\_temp\_path /tmp 1 2;

gzip on;  
gzip\_http\_version 1.0;  
gzip\_comp\_level 2;  
gzip\_proxied any;  
gzip\_types text/plain text/css application/x-javascript  
application/xml application/xml+rss text/javascript;

# nginx virtual host configuration file

# to be included by nginx.conf

# Load balance to mongrels

upstream mongrel\_cluster {  
server server1:3000;  
server server1:3001;  
…  
server server1:3007;

server server2:3000;  
server server2:3001;  
…  
server server2:3007;

}

# Begin virtual host configuration

server {

# Familiar HTTP settings

listen 443;

ssl on;

ssl\_certificate /usr/local/nginx/certs/server.crt;

ssl\_certificate\_key /usr/local/nginx/certs/server.key;

server\_name localhost;  
root /home/usr/app/current/public;  
access\_log /var/log/nginx/localhost.access.log main;  
error\_page 500 502 503 504 /500.html;  
client\_max\_body\_size 50M;

# First rewrite rule for handling maintenance page

if (-f $document\_root/system/maintenance.html) {  
rewrite ^(.\*)$ /system/maintenance.html last;  
break;  
}

location / {

```
 proxy_set_header X-FORWARDED_PROTO https;

index index.html index.htm;
# Forward information about the client and host
# Otherwise our Rails app wouldn't have access to it
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_max_temp_file_size 0;
# Directly serve static content
location ~ ^/(images|javascripts|stylesheets)/ {
  expires 10y;
}
if (-f $request_filename) {
  break;
}
# Directly serve cached pages
if (-f $request_filename.html) {
  rewrite (.*) $1.html break;
}
# Otherwise let Mongrel handle the request
if (!-f $request_filename) {
  proxy_pass http://mongrel_cluster;
  break;
}

```

}  
}  
}
