Reputation: 2577
I'm messing around with aws, and want to deploy multiple apps to my free tier aws account.
I'd like to have nginx point to "ec-2-site.com/first-app" and "ec-2-site.com/second-app.
Here are my current config files (basically guess and checking from 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;
}
}
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? Am I going bout this all wrong?
Thanks
Upvotes: 2
Views: 1027
Reputation: 461
I didn't check the railscast but I've found some problems in your configuration.
First is on line 50 you misspelled the address.
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.
Upvotes: 1