Rails redirects failure when configuring nginx & unicorn

I set up my work on nginx and the unicorn as described in Railscasts episode 293.

When I try to redirect e.g.

class PostsController < ApplicationController def show redirect_to posts_path, :notice => "Test redirect" end end 

I am redirecting to http://unicorn/posts instead of http://mydomain.com/posts

Here is my nginx.conf for the application

 upstream unicorn { server unix:/tmp/unicorn.scvrush.sock fail_timeout=0; } server { listen 80 default deferred; # server_name example.com; root /var/apps/current/public; try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } keepalive_timeout 5; } 
+7
source share
1 answer

This works for me:

 upstream unicorn { server unix:/tmp/unicorn.example.sock fail_timeout=0; } server { listen 80; listen localhost; server_name www.example.com; keepalive_timeout 5; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # this is required for HTTPS: # proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } } 

and in my file. /config/unicorn.rb:

 # Listen on a Unix data socket listen "/tmp/unicorn.example.sock", :backlog => 64 
+5
source

All Articles