【问题标题】:Nginx, unicorn and multiple rails apps in subrirectories子目录中的 Nginx、独角兽和多个 Rails 应用程序
【发布时间】:2013-07-21 08:00:39
【问题描述】:

我在使用 aws,想将多个应用部署到我的免费层级 aws 帐户。

我想让 nginx 指向“ec-2-site.com/first-app”和“ec-2-site.com/second-app”。

这是我当前的配置文件(基本上是从this railscast 猜测和检查

upstream unicorn_chaos {
  server unix:/tmp/unicorn.chaos.sock fail_timeout=0;
}

upstream unicorn_blog {
  server unix:/tmp/unicorn.blog.sock fail_timeout=0;
}

server {
  listen 80 default deferred;

  location /chaos/ {
    #server_name http://ec2-50-16-81-170.compute-1.amazonaws.com/chaos;
    root /home/deployer/apps/chaos/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_chaos;
    }

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

  location /blog/ {
    # server_name example.com;
    root /home/deployer/apps/blog/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)blog;
    }

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

这是我得到的错误:

 nginx: [emerg] named location "@unicorn_chaos" can be on the server level only in /etc/nginx/sites-enabled/chaos:23

显然@unicorn_appname 指令不应该在那里,但它应该在哪里呢?这一切都错了吗?

谢谢

【问题讨论】:

  • 一个天真的问题,但上面给出的整个代码是在http {} 块内吗?
  • 你是怎么解决这个问题的?
  • 我没有解决。这是一个个人 aws 服务器,从那时起我就没有在它上面工作太多了。
  • 有个话题我自己回答了,看看:stackoverflow.com/questions/18134046/…

标签: ruby-on-rails nginx unicorn


【解决方案1】:

我没有检查 railscast,但我发现您的配置存在一些问题。

首先是在第 50 行,您拼错了地址。

第二个是你应该把命名的位置放在位置之外。

您的层次结构如下所示

server
    location app1
        try_files @unicorn
        location @unicorn
            proxy_pass unicorn_app1
    location app2
        try_files @unicorn
        location @unicorn
            proxy_pass unicorn_app2

试试这个

server
    location app1
        try_files unicorn_app1
    location @unicorn_app1
        proxy_pass unicorn_app1

    location app2
        try_files @unicorn_app2
    location @unicorn_app2
        proxy_pass unicorn_app2

重要的是保持它们的名称唯一,并将它们放在相同的服务器级别。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-10
    • 2015-06-28
    • 2015-09-27
    • 1970-01-01
    • 2012-09-11
    • 2020-10-17
    • 2015-12-01
    • 1970-01-01
    相关资源
    最近更新 更多