开发者

Getting Nginx to forward to Thin on EC2

开发者 https://www.devze.com 2023-03-13 01:08 出处:网络
I\'m struggling to get Nginx to proxy my :80 traffic onto my thin cluster. At the moment.. nothing happens. See http://ec2-50-19-75-170.compute-1.amazonaws.com/

I'm struggling to get Nginx to proxy my :80 traffic onto my thin cluster.

At the moment.. nothing happens. See http://ec2-50-19-75-170.compute-1.amazonaws.com/

See below for my config files:

My etc/nginx/sites-enabled/dankit config file looks li开发者_JAVA百科kes this

upstream thin {
     server 0.0.0.0:3000;
     server 0.0.0.0:3001;
     server 0.0.0.0:3002;
}

server {
    listen 80;
    server_name ec2-50-19-174-64.compute-1.amazonaws.com;

    root /home/ubuntu/apps/dankit-rails;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect false;

      if (-f $request_filename/index.html) {
        rewrite (.*) $1/index.html break;
      }
      if (-f $request_filename.html) {
        rewrite (.*) $1.html break;
      }
      if (!-f $request_filename) {
        proxy_pass http://thin;
        break;
      }
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
      root html;
    }
}

I then ran: sudo ln -s sites-available/dankit sites-enabled/dankit

/etc/thin/dankit.yml

pid: tmp/pids/thin.pid
address: 0.0.0.0
timeout: 30
port: 3000
log: log/thin.log
max_conns: 1024
require: []

max_persistent_conns: 512
environment: production
servers: 3
daemonize: true
chdir: /home/ubuntu/apps/dankit-rails

and just to confirm both are running:

ubuntu@domU-12-31-39-06-7A-F8:/etc/nginx/sites-available$ ps -ef | grep -i thin root 923 1 2 16:06 ? 00:00:09 thin server (0.0.0.0:3000)

root 934 1 1 16:06 ? 00:00:09 thin server (0.0.0.0:3001)

root 945 1 1 16:06 ? 00:00:08 thin server (0.0.0.0:3002)

ubuntu 971 817 0 16:14 pts/0 00:00:00 grep -i thin ubuntu@domU-12-31-39-06-7A-F8:/etc/nginx/sites-available$ ps -ef | grep -i nginx root 542 1 0 16:04 ? 00:00:00 nginx: master process /usr/sbin/nginx www-data 545 542 0 16:04 ? 00:00:00 nginx: worker process


My thin servers start OK and the logs in the rails dir don't show any errors.

I'm starting to think it's a security issue with an ec2 security group. I have however added TCP for 0.0.0.0/0 3000-3030 and the usual :80 and ssh.

This is driving me mental! Any suggestions would be greatly appreciated.


I then ran: sudo ln -s sites-available/dankit sites-enabled/dankit

The issue may be one of two things or both:

  1. ln -s /etc/nginx/sites-available/dankit /etc/nginx/sites-enabled/dankit
  2. chown nobody:nobody /etc/nginx/sites-enabled/dankit

I tend only to use the full path for the symbolic links ... maybe it's just a good habit, but I also found that nginx isn't happy if the permissions aren't configured right for enabled sites.


Maybe change all the 0.0.0.0's to 127.0.0.1 or localhost which points to 127.0.0.1. The difference between 0.0.0.0 and 127.0.0.1 is that the former refers to the localhost's physical interface(s), while the latter refers to a software interface.


Looking at this URL http://articles.slicehost.com/2008/5/27/ubuntu-hardy-nginx-rails-and-thin & your configuration match perfect, I don't think of any problem, though I would like you to verify few things.

Please verify the following stuffs:

  1. Change thin address to point to 127.0.0.1
  2. Make sure the firewall is OPEN for the port-number of thin & 80 for TCP connection. Not by looking at the amazon console but by running iptables command.
  3. Finally, make sure, your public-dns is CORRECT


Sorted it.

Anyone that can answer why the symlink was the problem can get the answer!

Thanks for all the feedback and help. Basically if anyone else runs into this problem... here's what it was.

I noticed when I removed configs from /etc/nginx/site-enabled it affected the server.

..OK that sounds right!

Now I noticed when I re-sym linked a config from /etc/nginx/site-available to /etc/nginx/site-enabled it had no effect. Even the default nginx default config didn't work.

so! there must be a problem here with symlink. I did a quick test by importing /etc/nginx/site-available/dankit into the main Nginx config and hey! site is up.

Therefore I believe my symlink command:

sudo ln -s sites-available/dankit sites-enabled/dankit

is bollocks. I gotta look into another solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消