Reputation: 7855
I've been following Ryan B's VPS deployment railscast:
http://railscasts.com/episodes/335-deploying-to-a-vps
nginx.conf file he suggest using doesn't work with subdomains. This is what he shows:
upstream unicorn {
server unix:/tmp/unicorn.blog.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/deployer/apps/<app name>/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control 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;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
Does anyone know how to set things up to support subdomains?
Upvotes: 1
Views: 2036
Reputation: 7855
It turns out (at least with linode.com), that handeling wildcard subdomains is pretty straight forward. You just need to add a *
host to the A record.
Also, in nginix, what I did was replaced:
# server_name example.com;
with:
server_name localhost;
I'm not sure that's even needed.
My actual issue had nothing to do with either the host or nginx. My situation was that I was using a random hashed URL as a security token during registration (so a user can't hijack an existing subdomain), but the type of hash I was using had issues so I needed to modify it.
I wasn't seeing any errors, I was just being redirected back to the signup page -- as is the correct behavior when the hashed URL has problems / doesn't match.
Anyway, once I fixed that, the whole subdomain thing was a non-issue.
Hope this helps anyone else who uses hashed URLs, subdomains, and is generally new to deployment.
Cheers.
Upvotes: 0
Reputation: 1736
You can uncomment line:
# server_name example.com;
replace example.com with your domain and add:
server_name example.com *.example.com;
or
server_name example.com blog.example.com;
Now all requests to domain and subdomains will go to the rails
Upvotes: 1