title: Why am I getting 404 errors with Sinatra with Passenger under nginx?
body: <p>I have a Sinatra-based app that runs fine locally.</p>
  
  <p>I moved it to a nginx-based server with Passenger and now all my links to files in my apps <code>/public</code> are returning 404 errors. The primary app runs, is able to access the HAML templates in <code>/view</code>, which render correctly. The files exist and permissions are correct; I can open and edit them so I know they're there.</p>
  
  <p>In my HAML templates I'm referring to the files that I can't access like this:</p>
  
  <pre><code>%script{ :src =&gt; 'js/jquery.js' }
  %link{ "rel" =&gt; "stylesheet", "href" =&gt; "styles/input.css" }
  </code></pre>
  
  <p>My <code>config.ru</code> has gone through a lot mutations while I try to find the problem. Currently I have:</p>
  
  <pre><code>require 'sinatra'
  require './peering_template.rb'
  
  root_dir = File.dirname(__FILE__)
  
  # disable :run
  # set :root, root_dir
  # set :views, File.join(File.dirname(__FILE__), 'views')
  # set :environment, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development)
  
  run Sinatra::Application 
  </code></pre>
  
  <p>The app exists in <code>/home/apps/peering_template</code>.</p>
  
  <p>The web space is <code>/home/webapps</code>.</p>
  
  <p>There is a soft-link in <code>/home/webapps</code> like this: <code>peering_template -&gt; /home/apps/peering_template/public/</code>.</p>
  
  <pre><code>/home/webapps/
  `-- peering_template -&gt; /home/apps/peering_template/public/
  </code></pre>
  
  <p>The pertinent part of nginx.conf for this config is:</p>
  
  <pre><code>server {
      listen      3000;
      server_name my_servers_name;
      root        /home/webapps;
  
      passenger_enabled  on;
      passenger_base_uri /peering_template;
  }
  </code></pre>
  
  <p>Obviously, my server's name is different.</p>
  
  <p>The pertinent part from nginx' error.log is like this:</p>
  
  <pre><code>"/home/webapps/js/jquery.js" failed (2: No such file or directory), request: "GET /js/jquery.js HTTP/1.1"
  </code></pre>
  
  <p>As near as I can tell this fits the directions for an "<a href="http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_rack_to_sub_uri" rel="nofollow">nginx and passenger configuration using sub-URIs</a>". What am I missing?</p>
  
  <hr>
  
  <pre><code>/home/apps/peering_template/
  |-- config.ru
  |-- lib
  |   |-- bgp-config.rb
  |   |-- ios-xr-config.rb
  |   |-- ipv4_ipv6_grammar.rb
  |   `-- ipv4_ipv6_grammar.treetop
  |-- nginx.conf
  |-- peering_template.rb
  |-- public
  |   |-- js
  |   |   |-- jquery-1.6.min.js
  |   |   |-- jquery-ui-1.8.12.custom.zip
  |   |   |-- jquery.js -&gt; jquery-1.6.min.js
  |   |   `-- scripts.js
  |   |-- peering_template_tool.htm
  |   `-- styles
  |       `-- input.css
  |-- spreadsheets
  |   |-- Peering Template-AMS-IX.xlsx
  |   `-- Peering Template-IOS-XR-ASH1.xlsx
  |-- tmp
  |   `-- always_restart.txt
  `-- views
      |-- index.haml
      `-- output.haml
  </code></pre>
  
  <p>I'm not sure if it matters but this is on a <code>CentOS release 5.3 (Final)</code> host, running <code>nginx/1.0.0</code> and <code>passenger (3.0.7)</code>.</p>