christiangenco / dbinbox

an inbox for your Dropbox
dbinbox.com
MIT License
285 stars 42 forks source link

Sending a message shows IP address as 127.0.0.1 #24

Closed wizardfrag closed 11 years ago

wizardfrag commented 11 years ago

When uploading a text file via the "send message" interface, the file shows as such:

Uploaded 2013-08-05 05:04:46 -0400 from 127.0.0.1

Your message

This, obviously, is not the IP address it was uploaded from. Seems to be caused by a proxy in front of this application.

christiangenco commented 11 years ago

Ahh yes, you're right.

The error is happening on https://github.com/christiangenco/dbinbox/blob/0032068f748c5ca4c6f8c2f5647e18230e5be4ba/app.rb#L281

Not sure what the fix for this would be. Wanna take a crack at it?

wizardfrag commented 11 years ago

The code should work fine. This is most likely a configuration issue. Make sure your proxy is sending the X_FORWARDED_FOR header. In nginx you should just be able to add a line:

include proxy_params

to the location that defines the proxy_pass

christiangenco commented 11 years ago

Here's what I have right now in nginx:

157   upstream dbinbox.com{
158     server 127.0.0.1:3200;
159   }·
160   server{
161     listen 80;
162     server_name dbinbox.com;
163     client_max_body_size 100M;
164     root /u/apps/dbinbox/current/;
165     access_log /u/apps/dbinbox/current/log/thin.log;
166     error_log /u/apps/dbinbox/current/log/error.log;
167     location / {
168       proxy_pass http://dbinbox.com;
169     }
170     error_page 500 502 503 504 /50x.html;
171   }

Do I just add include proxy_params below line 168?

christiangenco commented 11 years ago

Oh hey! That fixed it. I did this instead, but I think it's functionally equivalent:

157   upstream dbinbox.com{
158     server 127.0.0.1:3200;
159   }·
160   server{
161     listen 80;
162     server_name dbinbox.com;
163     client_max_body_size 100M;
164     root /u/apps/dbinbox/current/;
165     access_log /u/apps/dbinbox/current/log/thin.log;
166     error_log /u/apps/dbinbox/current/log/error.log;
167     location / {
168       proxy_pass http://dbinbox.com;
169       proxy_set_header Host $host;
170       proxy_set_header X-Real-IP $remote_addr;
171       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
172     }
173     error_page 500 502 503 504 /50x.html;
174   }