Problem configuring Nginx to host SpreeCommerce - 502 error

I have had a terribly difficult time deploying SpreeCommerce, despite
(or perhaps because of) following the Spree documentation. I have
eventually gotten to the point where the Capistrano deployment runs
through entirely, but I seem to have configured Nginx incorrectly, as I
am getting a “502 - Bad Gateway” error. My current nginx.conf and site
configuration files are attached; I have tried the recommendations from
several different sources but no combination of options seems to have
any effect.

looks like a recursion to me, no?
you point your nginx.conf to proxy_pass
to http://www.masterjoestoybox.net/
and then you define with your mjtb
a config that listens to www.masterjoestoybox.net
and proxy_passes to http://www.masterjoestoybox.net/

and you configure a upstream unicorn_server in your
nginx.conf but never use it?

maybe you can throw away the mjtb - config

btw,

regards,

mex

Posted at Nginx Forum:

Ah, thank you. Removing the site configuration file did fix the gateway
error, but now the server is still pointing at the default Nginx welcome
page. Can you (or anyone else here) give me any advice on how to get the
server to point to my actual service?

BTW, you pointed out that there was an upstream Unicorn server
configured, something that I wasn’t sure was necessary when I was
following the instructions; the Unicorn workers should in fact be on the
same host as the web server. I had thought that the way it was defined,
using a temporary socket, was correct for the layout I have, but it
sounds as if I misunderstood this (and probably a lot of other things).
Can you advise me on configuring the Unicorn workers correctly?

If there is any additional information or any other configuration files
which would help, please let me know.

Joseph O. Wrote:

Ah, thank you. Removing the site configuration file did fix the
gateway
error, but now the server is still pointing at the default Nginx
welcome
page. Can you (or anyone else here) give me any advice on how to get
the
server to point to my actual service?

proxy_pass should do the trick

maybe you post your actual config.

Posted at Nginx Forum:

I’m not sure what you mean here; Which aspects of the actual
configuration? The Capistrano deployment, the Unicorn.rb file, or some
other part of the Nginx configuration? I’ve attached the former two,
with the sensitive data masked out of course, but I’m not certain what
else you would need.

I did correct the socket path (it is now set to /tmp/spree.sock in both
the deploy.rb and nginx.conf), but I am unclear about what to do with
the proxy_pass settings.

your nginx-conf please that points to your upstream <and defines your
listening server {} :slight_smile:

Posted at Nginx Forum:

sigh Clearly I am missing something here, as the only nginx.conf file
I have is the one I posted last night. There is no upstream server; the
code for that was from the example config file I was trying to modify
for my purposes.

It seems that this copypasta approach isn’t adequate for setting this up
properly (I can’t say I’m too surprised, but the Spree documentation I
was going by implied that it would be), and that I will need to actually
understand how Nginx works if I am to get anywhere with this. At this
point, a tutorial or other documentation is probably what I need most.
I had hoped that the problem was fairly simple, and could be fixed by
some tweaking; it now is clear that the Spree documentation isn’t work
the electrons it is printed on.

OK, so I’ve gone through the documentation on the Nginx wiki, and I
still only have a minimal grasp on how to configure the it to serve
Spree via Unicorn. Things are now back where they started (with a 502
error), but I am making some progress, however, in that the server now
points to the custom error pages I made, rather than the default ones.
Oh well…

Attached is the current version of my nginx.conf file.

Joseph O. Wrote:

ok, first make sure your railsapp is loading as expected and
working w/out nginx in front; you can check it from that machine using
w3m/lynx or telnet. if this works we’ll check the nginx-part.

sigh Clearly I am missing something here, as the only nginx.conf
file
I have is the one I posted last night. There is no upstream server;
the
code for that was from the example config file I was trying to modify
for my purposes.

you define a upstream {} section but you dont use it later, instead of
proxy_pass $upstream you define proxy_pass to use a hostname
instead of your upstream; thats a mismatch in your config

It seems that this copypasta approach isn’t adequate for setting this
up properly

+1 :slight_smile:

you’ll find some howtos and best-practice-guides for various
applications
here: Getting Started | NGINX

but understanding what you’re doing is key for long-time-happyness.
basically, your setup is quite simple and straight-forward.

regards,

mex

Posted at Nginx Forum:

ok,your config is a little confused.

in your @ruby - part you should proxy_pass to your unicorn - server
proxy_pass http://unicorn_server;
(thats why you put your definition there :slight_smile:


OK, so I’ve gone through the documentation on the Nginx wiki, and I
still only have a minimal grasp on how to configure the it to serve
Spree via Unicorn. Things are now back where they started (with a 502
error), but I am making some progress, however, in that the server now

points to the custom error pages I made, rather than the default ones.

Oh well…

Attached is the current version of my nginx.conf file.

nginx Info Page
Posted at Nginx Forum:
Re: Problem configuring Nginx to host SpreeCommerce - 502 error