Question about configuring Nginx and CB properly on AWS

110 views
Skip to first unread message

Hrishikesh Choudhari

unread,
Oct 24, 2013, 4:19:50 PM10/24/13
to chica...@googlegroups.com
Hi guys, 

I've gotten my CB project to work properly on a micro instance on AWS.

However, my browser isn't loading the page at all.

A wget from instance to http://127.0.0.1:8001/static/index.html works properly, which means mochiweb is serving content.

My nginx config has this block - I picked it from http://beebole.com/blog/erlang/web-application-on-erlang-configure-nginx-with-mochiweb/

server {
listen 80 default;
server_name mochiweb;

location / {
index index.html;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}


From the same micro instance, wget http://ec2-54-254-16-44.ap-southeast-1.compute.amazonaws.com/static/index.html works, and returns the contents of the HTML.

However, there's no response from the browser, and neither if I do a wget to http://ec2-54-254-16-44.ap-southeast-1.compute.amazonaws.com/static/index.html from my local desktop.

1. All I want to know is that, have I configured the port forwarding properly in nginx? If yes, then I'll begin debugging the config of my AWS instance. Maybe I messed up in the security groups section..

2. Is it proper to keep the /var/erl/app-name/priv/static path as my root? Or just /var/erl/app-name ?

Hrishikesh Choudhari

unread,
Oct 24, 2013, 4:50:26 PM10/24/13
to chica...@googlegroups.com
Alright I got it working!

I had set the security group config incorrectly a few days ago, and completely missed it while debugging this issue. The security group  didn't have any rules for HTTP or HTTPS at all.. 

However, I would still require help for the 2nd question.

 Is it proper to keep the /var/erl/app-name/priv/static path as my root? Or just /var/erl/app-name ?

Evgeny M

unread,
Oct 24, 2013, 6:13:54 PM10/24/13
to chica...@googlegroups.com
Here's how I do nginx proxying (not on amazon, but it doesn't matter):

upstream myservercboss {
        server 127.0.0.1:8001;
}
server {
        listen 80;
        server_name myserver.com;
        set_real_ip_from  127.0.0.1;
        real_ip_header     X-Real-IP;
        chunked_transfer_encoding on;
        location /static/ {
                root /home/sites/myserver.com/priv/;
        }
        location / {
                proxy_pass  http://myservercboss;
                proxy_http_version 1.1;
                proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

        }

}

As you can see, no root directive altogether for /, as requests for dynamic content are proxied to CB server, and another location for static files, which are served by nginx directly.

пятница, 25 октября 2013 г., 0:50:26 UTC+4 пользователь Hrishikesh Choudhari написал:

Hrishikesh Choudhari

unread,
Oct 29, 2013, 11:21:17 AM10/29/13
to chica...@googlegroups.com
Hi Evgeny, 

I have the following in my nginx.conf:

        upstream myservercboss {
                server 127.0.0.1:8001;
        }

        server {
                listen 80 default;
                server_name  ec2-54-254-26-120.ap-southeast-1.compute.amazonaws.com;
                set_real_ip_from 127.0.0.1;
                real_ip_header X-Real-IP;
                chunked_transfer_encoding on;
                location /static/ {
                        root /var/erl/steryle/priv/static;
                }
                location / {
                        proxy_pass              http://ec2-54-254-26-120.ap-southeast-1.compute.amazonaws.com;
                        proxy_http_version      1.1;
                        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
                         proxy_buffering        off;
                        proxy_redirect          off;
                        proxy_set_header        Host            $host;
                        proxy_set_header        X-Real-IP       $remote_addr;
                        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                }
        }

I hope I'm not making any beginner's stupid mistakes in this conf file.

The problem is, CB's production mode can serve http://ec2-00.00.00.0.ap-southeast-1.compute.amazonaws.com/static/index.html, but gives 404 for http://ec2-00.00.00.0.ap-southeast-1.compute.amazonaws.com/greeting/hello

However, for CB's dev modehttp://ec2-00.00.00.0.ap-southeast-1.compute.amazonaws.com/greeting/hello works properly!

What could be going wrong?

Hrishikesh Choudhari

unread,
Oct 29, 2013, 11:31:29 AM10/29/13
to chica...@googlegroups.com
Damn it!..

Forgot to do sudo ./rebar compile

Working fine with production mode now.

Thanks for the nginx config. :)

On Friday, 25 October 2013 01:49:50 UTC+5:30, Hrishikesh Choudhari wrote:

Alexey Marunin

unread,
Oct 29, 2013, 12:35:36 PM10/29/13
to chica...@googlegroups.com
Evgeny, is this config for production server?

вторник, 29 октября 2013 г., 18:21:17 UTC+3 пользователь Hrishikesh Choudhari написал:

Evgeny M

unread,
Oct 30, 2013, 8:32:03 AM10/30/13
to chica...@googlegroups.com
Yes it is.
You may also add separate locations for favicon.ico and robots.txt.
Also  as you can see there's no logging.

вторник, 29 октября 2013 г., 20:35:36 UTC+4 пользователь Alexey Marunin написал:

Alexey Marunin

unread,
Oct 30, 2013, 5:33:28 PM10/30/13
to chica...@googlegroups.com
Thanks! 

среда, 30 октября 2013 г., 15:32:03 UTC+3 пользователь Evgeny M написал:
Reply all
Reply to author
Forward
0 new messages