502 Bad Gateway- Nginx and thin

I have install nginx 1.1.19 and thin 1.5.0 in Ubuntu 12.04 and I am
install redmine, when I try to access the page of redmine gives me the
following error: 502 Bad Gateway. In Nginx log reads:
2013/03/18 10:45:09 [crit] 13886#0: *11 connect() to
unix:/tmp/thin.0.sock failed (2: No such file or directory) while
connecting to upstream, client: 127.0.0.1, server:
redmine_nginx.ipp.com, request: “GET / HTTP/1.1”, upstream:
http://unix:/tmp/thin.0.sock:/”, host: “redmine_nginx.ipp.com”
thin configuration:

chdir: /var/www/redmine_nginx/
environment: production
address: 0.0.0.0
port: 3000
timeout: 30
log: /var/log/thin/redmine.log
#pid: /var/run/thin/redmine.pid
pid: tmp/pids/thin.pid
max_conns: 1024
max_persistent_conns: 512
require: []
wait: 30
servers: 1
daemonize: true
socket: /tmp/thin.sock
group: www-data
user: www-data

Nginx Service block:
upstream thin_cluster {
server unix:/tmp/thin.0.sock;

}

server {

listen 80; ## listen for ipv4

Set appropriately for virtual hosting and to use

server_name_in_redirect
server_name redmine_nginx.ipp.com;
server_name_in_redirect off;

access_log /var/log/nginx/localhost.access.log;
error_log /var/log/nginx/localhost.error.log;

Note: Documentation says proxy_set_header should work in location

block, but testing did not support this statement so it has

been placed here in server block

include /etc/nginx/proxy_opts;
proxy_redirect off;

Note: Must match the prefix used in Thin configuration for Redmine

or / if no prefix configured

location / {
root /var/www/redmine_nginx/public;

error_page 404  404.html;
error_page 500 502 503 504  500.html;

try_files $uri/index.html $uri.html $uri @redmine_thin_servers;
}

location @redmine_thin_servers {
proxy_pass http://thin_cluster;
}
}

the include /etc/nginx/proxy_opts;

Shared options used by all proxies

proxy_set_header Host $http_host;

Following headers are not used by Redmine but may be useful for

plugins and

other web applications

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

Any other options for all proxies here

client_max_body_size 10m;
client_body_buffer_size 128k;

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;

Hello!

On Mon, Mar 18, 2013 at 04:12:58PM +0100, Yunior Miguel A. wrote:

I have install nginx 1.1.19 and thin 1.5.0 in Ubuntu 12.04 and I am
install redmine, when I try to access the page of redmine gives me the
following error: 502 Bad Gateway. In Nginx log reads:
2013/03/18 10:45:09 [crit] 13886#0: *11 connect() to
unix:/tmp/thin.0.sock failed (2: No such file or directory) while
connecting to upstream, client: 127.0.0.1, server:
redmine_nginx.ipp.com, request: “GET / HTTP/1.1”, upstream:
http://unix:/tmp/thin.0.sock:/”, host: “redmine_nginx.ipp.com”
thin configuration:

[…]

This:

socket: /tmp/thin.sock

doesn’t match this:

server unix:/tmp/thin.0.sock;

and the mismatch explains the problem.


Maxim D.
http://nginx.org/en/donation.html

Whn I am go /tmp/thin.0.sock that file exist. Sometime when i am reset
the thin read thin:
/var/lib/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in
`block in require’: iconv will be deprecated in the future, use
String#encode instead.

I am put the same port and change server unix:/tmp/thin.sock;

and the log is the same.

On Mon, Mar 18, 2013 at 05:13:12PM +0100, Yunior Miguel A. wrote:

Hi there,

I am put the same port and change server unix:/tmp/thin.sock;

and the log is the same.

I’m not sure what exact configuration and log you are looking at in this
test, but if your nginx.conf says “unix:/tmp/thin.sock” and your nginx
error log says “connect() to unix:/tmp/thin.0.sock failed”, then your
actually-running nginx is not using that nginx.conf.

Alternatively, if your nginx.conf says “unix:/tmp/thin.sock” and your
nginx error log says “connect() to unix:/tmp/thin.sock failed”, then
that strongly suggests that your thin is not listening on that socket.

So either make sure that thin is doing what you expect, or make sure
that nginx is doing what you expect, depending on what your test showed.

f

Francis D. [email protected]

On Mon, Mar 18, 2013 at 04:12:58PM +0100, Yunior Miguel A. wrote:

Hi there,

I have install nginx 1.1.19 and thin 1.5.0 in Ubuntu 12.04 and I am
install redmine, when I try to access the page of redmine gives me the
following error: 502 Bad Gateway. In Nginx log reads:
2013/03/18 10:45:09 [crit] 13886#0: *11 connect() to
unix:/tmp/thin.0.sock failed (2: No such file or directory) while

Where did you tell thin to listen?

Where did you tell nginx that thin would be listening?

Are they the same?

f

Francis D. [email protected]

thin => socket: /tmp/thin.sock
nginx => server unix:/tmp/thin.0.sock;

would be the problem i think.

Am 18.03.2013 20:53, schrieb Yunior Miguel A.:

Thans for all. The end configuration:

thin configuration:

chdir: /var/www/redmine/
environment: production
address: 127.0.0.1
port: 3000
timeout: 30
log: /var/log/thin/gespro.log
pid: tmp/pids/thin.pid
max_conns: 1024
max_persistent_conns: 512
require: []
wait: 30
servers: 1
daemonize: true
socket: /tmp/thin.sock
group: www-data
user: www-data

ngin configuration:

upstream thin_cluster {
server unix:/tmp/thin.0.sock;

server unix:/tmp/thin.1.sock;

server unix:/tmp/thin.2.sock;

}

server {

listen 80; ## listen for ipv4

Set appropriately for virtual hosting and to use

server_name_in_redirect
server_name redmine.ipp.uci.cu;
server_name_in_redirect off;

access_log /var/log/nginx/localhost.access.log;
error_log /var/log/nginx/localhost.error.log;

Note: Documentation says proxy_set_header should work in location

block, but testing did not support this statement so it has

been placed here in server block

include /etc/nginx/proxy_opts;
proxy_redirect off;

Note: Must match the prefix used in Thin configuration for Redmine

or / if no prefix configured

location / {
root /var/www/redmine/public;

error_page 404  404.html;
error_page 500 502 503 504  500.html;

try_files $uri/index.html $uri.html $uri @redmine_thin_servers;
}

location @redmine_thin_servers {
proxy_pass http://thin_cluster;
}
}

thanks for all.

On Mon, Mar 18, 2013 at 08:53:10PM +0100, Yunior Miguel A. wrote:

Hi there,

I see that I was wrong in assuming how thin works.

thin configuration:

servers: 1
socket: /tmp/thin.sock

It looks like the actual file name used for the socket can add a
“.integer” before the final “.” in the configured socket file name,
with the integer going from 0 up to one below the number of servers.

So this bit:

ngin configuration:

upstream thin_cluster {
server unix:/tmp/thin.0.sock;

server unix:/tmp/thin.1.sock;

server unix:/tmp/thin.2.sock;

}

is correct, despite looking odd to my non-thin eyes.

It’s good that you found a configuration that works for you.

From the initial error message reported, I can only assume that thin
wasn’t running in that mode at the time you tested.

f

Francis D. [email protected]