1

我在多租户上关注了一个简单的 railscasts 插曲, 现在我的应用程序中的所有租户都进入了他们的子域,该子域在我的开发系统上本地工作,但是当我在我的 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;
}
4

1 回答 1

1

I had no problem doing this. First you need to create an A record in any DNS provider that you are using. for example create a DNS record:

it.shopnany.com

Then you'll have to update your nginx config template for this particular deployment. It can be as follows:

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;
}

This worked for me. Now I have two different applications running on my www and it subdomains.

于 2013-05-08T16:09:48.967 回答