title: nginx (+ passenger) doesn't seem to run on port 80
body: <p>I have nginx (<em>with</em> <strong><em>passenger</em></strong>) installed on my user account (<em>via</em> <strong><em>homebrew</em></strong>). For a few hours I thought the thing just refuses to work, as I couldn't get any Rails3 application to respond on a simple nginx-declared location. After much deliberation (<em>AKA trial-and-error</em>) I came to conclusion that it does work, but refuses to use port 80.</p>
  
  <p>I know, that a <strong>homebrew</strong> installation is a per user installation, thus it should not be able to run on root-only ports (<em>ie. ports 1024 and below</em>), but <strong>homebrew itself</strong> (<em>and various sources on the net</em>) suggest that simply running the server via <code>sudo nginx</code> would suffice to allow it to use port 80.</p>
  
  <p>These are the important files of the configuration that <strong>does</strong> work:</p>
  
  <h3>/etc/hosts:</h3>
  
  <pre><code>##
  # Host Database
  #
  # localhost is used to configure the loopback interface
  # when the system is booting.  Do not change this entry.
  ##
  127.0.0.1       doomhub.local localhost
  255.255.255.255 broadcasthost
  ::1             localhost 
  fe80::1%lo0     localhost
  </code></pre>
  
  <h3>/usr/local/etc/nginx/nginx.conf:</h3>
  
  <pre><code>#user  nobody;
  worker_processes  1;
  
  events {
      worker_connections  1024;
  }
  
  
  http {
      passenger_root /Users/ellmo/.rvm/gems/ruby-1.9.3-p125/gems/passenger-3.0.18/;
      passenger_ruby /Users/ellmo/.rvm/rubies/ruby-1.9.3-p125/bin/ruby;
  
      include       mime.types;
      default_type  application/octet-stream;
  
      access_log  logs/access.log;  #main;
  
      sendfile        on;
      #tcp_nopush     on;
  
      #keepalive_timeout  0;
      keepalive_timeout  65;
  
      #gzip  on;
  
          server {
              server_name doomhub.local;
              listen 8080;
              root /Users/ellmo/rails/doomhub/public;
              passenger_enabled on;
              passenger_use_global_queue on;
              rails_env development;
          }
  }
  </code></pre>
  
  <p>When I change the application's server port to <code>80</code>, I naturally will - upon restart - receive a:</p>
  
  <p><code>
  nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
  </code></p>
  
  <p>...but when I <code>sudo</code> it, the error won't show, the process will start with <code>root</code> as its owner. However opening <code>http://doomhub.local</code> in the browser returns nothing (<em>well, technically it's a "browser could not resolve the address" error, but I get no other errors, no nginx error</em>). I get no logs, no nothing.</p>
  
  <p>When I change the listening port back to 8080 (or anything else) it works like a charm when I run it as a regular user... but then I really want to use <code>http://doomhub.local</code> in my browser rather than <code>http://doomhub.local:8080</code>.</p>
  
  <p>Is there anything that would block OSX apps from listening on port 80, that I'm missing? As you can see I <strong>CAN</strong> use it, so there's no other process in the way. It just doesn't listen to anyhting.</p>
  
  <p>Is there any way to treat <code>8080</code> in the browser as a "normal" <strong>http</strong> port?</p>
  
  <h1>EDIT:</h1>
  
  <p>Specifying passenger users as <a href="https://stackoverflow.com/users/1939031/jan-schejbal">Jan Schejbal</a> suggested didn't solve the issue for me, after a while I ended up creating <strong>rvm</strong> wrappers for passenger (<em>rather than allowing it to use clear ruby binaries</em>) as described in this great post:</p>
  
  <p><a href="http://everydayrails.com/2010/09/13/rvm-project-gemsets.html" rel="nofollow noreferrer">http://everydayrails.com/2010/09/13/rvm-project-gemsets.html</a></p>
  
  <p>Thanks to creating a <strong>passenger/bundler-only rvm wrapper</strong> I managed to get the application running when I start nginx as <strong>root</strong>. I can specify both root-only and user-allowed listening ports (<em>ie. I tested both 8080 and 81</em>) and the application is served fine even with all the gems that are <strong>NOT</strong> related to the wrapper binary. Yet...</p>
  
  <p>...still I get absolutely nothing on port 80.</p>