简体   繁体   English

使用capistrano将子域的Rails部署到nginx / unicorn设置-如何?

[英]Deploying Rails with subdomains using capistrano to an nginx/unicorn setup — how?

I've been following Ryan B's VPS deployment railscast: 我一直在关注Ryan B的VPS部署轨道:

http://railscasts.com/episodes/335-deploying-to-a-vps http://railscasts.com/episodes/335-deploying-to-a-vps

nginx.conf file he suggest using doesn't work with subdomains. 他建议使用的nginx.conf文件不适用于子域。 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? 有谁知道如何设置东西来支持子域?

You can uncomment line: 您可以取消注释行:

# server_name example.com;

replace example.com with your domain and add: 用您的域替换example.com并添加:

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 现在,所有对域和子域的请求都将移到轨道上

It turns out (at least with linode.com), that handeling wildcard subdomains is pretty straight forward. 事实证明(至少使用linode.com),处理通配符子域非常简单。 You just need to add a * host to the A record. 您只需要向A记录添加*主机。

Also, in nginix, what I did was replaced: 另外,在nginix中,我所做的被替换了:

# 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. 我的实际问题与主机或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. 我的情况是我在注册时使用了一个随机的哈希URL作为安全令牌(因此用户不能劫持一个现有的子域),但是我使用的哈希类型存在问题,因此我需要对其进行修改。

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. 希望这对使用散列URL,子域并且通常是部署新手的其他用户有所帮助。

Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Nginx,Unicorn,Postgres和Capistrano将Rails应用程序部署到Digital Ocean:Nginx eror - Deploying Rails app using Nginx, Unicorn, Postgres and Capistrano to Digital Ocean : nginx eror Rails + ActionCable + Nginx + Unicorn设置 - Rails + ActionCable + Nginx + Unicorn Setup 使用(unicorn和nginx)在rails app uri上部署sinatra app - Deploying sinatra app on rails app sub uri using( unicorn and nginx) 使用capistrano在track app上部署ruby - cap deploy:setup faileding - deploying ruby on rails app using capistrano - cap deploy:setup failing Rails + Nginx + Unicorn-部署时未创建unicorn.sock文件 - Rails + Nginx + Unicorn - unicorn.sock file is not created when deploying 在nginx和unicorn设置上Rails重定向失败 - Rails redirect fails on nginx & unicorn setup 使用带Nginx和Unicorn的Websockets的Rails? - Rails using Websockets with Nginx and Unicorn? 在rails中设置一个带有unicorn,nginx和capistrano的虚拟主机 - setting up a virtual host with unicorn, nginx and capistrano in rails Rails,Capistrano,Nginx,Unicorn - 应用程序已经初始化(RuntimeError) - Rails, Capistrano, Nginx, Unicorn - Application has been already initialized (RuntimeError) Ruby on Rails Nginx,独角兽,Capistrano VPS托管错误 - Ruby on rails nginx , unicorn, capistrano vps hosting error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM