简体   繁体   English

子区域中的Nginx,独角兽和多个Rails应用

[英]Nginx, unicorn and multiple rails apps in subrirectories

I'm messing around with aws, and want to deploy multiple apps to my free tier aws account. 我正忙着使用AWS,并想将多个应用程序部署到我的免费AWS帐户中。

I'd like to have nginx point to "ec-2-site.com/first-app" and "ec-2-site.com/second-app. 我想让nginx指向“ ec-2-site.com/first-app”和“ ec-2-site.com/second-app”。

Here are my current config files (basically guess and checking from this railscast 这是我当前的配置文件(基本上是从该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;
  }
}

Here is the error I'm getting: 这是我得到的错误:

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

Obviously that @unicorn_appname directive shouldn't be there, but where should it be? 显然,@ unicorn_appname指令不应存在,但应该在哪里? Am I going bout this all wrong? 我会把这一切弄错吗?

Thanks 谢谢

I didn't check the railscast but I've found some problems in your configuration. 我没有检查railscast,但是在您的配置中发现了一些问题。

First is on line 50 you misspelled the address. 首先是第50行,您拼错了地址。

Second is that you should put named locations out of the locations. 其次,您应该将命名位置放到位置之外。

Your hierarchy looks like this 您的层次结构如下所示

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

Try this 尝试这个

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

The important is to keep their names unique , and put them in the same server level. 重要的是要保持其名称唯一 ,并将它们置于同一服务器级别。

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

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