Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to set my rails app to a specific subdomain. I'm using an ec2 instance with a bitnami rubystack VM I developed the app using it with the ip of the server, so I know that rails and the app work.

${nginx-dir}/conf/nginx.conf

server {
listen       80 default_server;
server_name  _;
server_name_in_redirect off;
proxy_intercept_errors on;
return 401;
}
include "/opt/bitnami/nginx/conf/vhosts/*.conf";

${nginx-dir}/conf/vhosts/backend.conf

upstream thin_instances {
   server 0.0.0.0:3000;
   server 0.0.0.0:3001;
   server 0.0.0.0:3002;
   fair;
}
 server {
    # port to listen on. Can also be set to an IP:PORT
    listen 80;
    server_name backend.mydomain.com;
      root /opt/bitnami/projects/myappname/public;
    location / {

      proxy_pass http://thin_instances;
      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;
      if (!-f $request_filename) {
        proxy_pass http://thin_instances;
      break;
      }
     }
}

This is what I get when I do a post or get request to the domain

<html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.2.4</center>
</body>
</html>
share|improve this question

2 Answers 2

Two things to be aware of:

  1. The server block in nginx.conf supersedes your custom server definition, since that is presumably being used before the custom configs are included (the first server section that matches the Host header, since it is a wildcard here, will be the configuration that is used, unless you set server_name ""). Since document_root isn't set in the default server block, it will default to something like /var/www which may not be what you want.
  2. Keep in mind the default nginx configuration in most distros is probably including all the .conf files from /etc/nginx/sites-enabled. You'll probably want to create a symlink in that directory to the .conf file in /etc/nginx/sites-available. (If you removed everything else from nginx.conf e.g. your listing is the contents verbatim of nginx.conf, you'll probably want something like include /etc/nginx/sites-enabled/*; at the end.
share|improve this answer
    
I've added some modifications. Now I'm getting the 401 error on any case –  Pacu Dec 3 '12 at 18:24
    
Try setting server_name ""; in your default server definition. (I've edited the comments above, I was thinking of the directive in older nginx versions). Also, what are you seeing in your nginx error/access logs? –  blackbox222 Dec 3 '12 at 18:39
    
I've tried removing the default and letting the subdomain server block on it own, but it does not work either. Also tried copy/paste on the vhosts/backend.conf on the nginx.conf file to make sure that it was being included. This is driving me nuts and every single article on nginx is the freaking happy path. Thank you very much for your help. ps: the access.log and errors.log don't show anything strange. –  Pacu Dec 3 '12 at 18:59
up vote 0 down vote accepted

I have to remark that the answer provided by blackbox222 help me to determine the root of the problem. Finally, I changed my DNS provider for one that could actually configure the A record properly and not use some sort of bizarre redirect.

TL;DR: make sure your DNS is configured properly

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.