繁体   English   中英

如何使用Unicorn和Nginx处理Rails中的子域

[英]how to Handle Subdomain in rails with unicorn, and nginx

我在多租户上遵循了一个简单的railscasts情节,现在我应用程序中的所有租户都进入了他们的子域,该子域在我的dev syatem上本地工作,但是由于我在vps系统上尝试了相同的过程,浏览器说找不到服务器。

我已经将域连接到我的IP并修改了我的Nginx文件,但仍然没有希望

用户进入其子域后,请求不会到达我的Rails应用。

关于这个的任何想法,否则我可能做对了。 谢谢

我的nginx_unicorn_file

upstream unicorn {
  server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  server_name shopnany.com *.shopnany.com;
  root <%= current_path %>/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;
}

我这样做没有问题。 首先,您需要在使用的任何DNS提供程序中创建A记录。 例如创建一个DNS记录:

it.shopnany.com

然后,您必须为此特定部署更新您的nginx配置模板。 可以如下所示:

upstream unicorn_<%= application %> {
  server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
}

server {
  listen 80;
  server_name it.shopnany.com;
  root <%= current_path %>/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_<%= application %>;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

这对我有用。 现在,我的www及其子域上运行了两个不同的应用程序。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM