簡體   English   中英

子區域中的Nginx,獨角獸和多個Rails應用

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

我正忙着使用AWS,並想將多個應用程序部署到我的免費AWS帳戶中。

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

這是我當前的配置文件(基本上是從該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指令不應存在,但應該在哪里? 我會把這一切弄錯嗎?

謝謝

我沒有檢查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

重要的是要保持其名稱唯一 ,並將它們置於同一服務器級別。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM