2013-05-10 85 views
2

我与aws混淆,并且想要将多个应用程序部署到我的免费层aws帐户。Nginx,独角兽和子轨道中的多轨应用程序

我想有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指令不应该存在,但这里应该是我要去回合所有这一切G?

感谢

+0

一个天真的问题,但是上面给出的'http {}'块内的整个代码? – Kashyap 2013-05-11 04:23:30

+1

你是如何解决这个问题的? – 2013-07-09 09:04:29

+0

我没有解决它。这是一个个人aws服务器,从那以后我一直没有做过这方面的工作。 – Squadrons 2013-07-09 14:56:34

回答

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 

重要的是要保持自己的名字独特,并把它们放在同一服务器水平。