I have set up my up to run on nginx and unicorn as described in Railscasts episode #293.
When I try to redirect, such as
class PostsController < ApplicationController
def show
redirect_to posts_path, :notice => "Test redirect"
end
end
I get redirected to http://unicorn/posts
instead of http://mydomain.com/posts
Here's my nginx.conf for the app
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;
}
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 ./config/unicorn.rb file:
# Listen on a Unix data socket
listen "/tmp/unicorn.example.sock", :backlog => 64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With