title: Best Practice For Structuring Multiple Projects in Nginx?
body: <p>First off, I'm going to apologize for the vagueness of my title. I do have a specific problem I'm encountering when creating my Nginx configs, but it's one that I've encountered several times, and I have a hard time believing there isn't a better way. I went with a vague title because I didn't feel I could describe the problem in such a small amount of text, and because I wanted to generalize it in the hopes of getting a better answer.</p>
  <p>Here's my problem-</p>
  <p>Let's say I have an Nginx server <code>example.com</code> and in my configuration file I have my server root set to <code>/directory/files</code>. I have a single location set up, we'll call it <code>/website</code>. I request the index file from <code>example.com/website</code>. The server returns my webpage, and on this webpage, I link to the location <code>/js/myfile.js</code> in a script tag. This is where my problem arises.</p>
  <p>So the browser sends out a request with host <code>example.com</code>, to the location <code>/js/myfile.js</code>. My server sees the request, but it doesn't find a location block for <code>/js/myfile.js</code>, so it sends back a status 404.</p>
  <p>Okay, so problem located- I serve my HTML from <code>/directory/files/website</code>, but I can't serve <code>/directory/files/js/myfile.js</code> because it quite literally doesn't exist (at least not at that location). Instead I have my JS located in <code>/directory/files/website/js</code> since project files are typically stored separately in their own directories for organization.</p>
  <p>So to summarize, my site tries to serve relative locations in links from the root directory of the server, which doesn't work because the HTML with the links was served one directory deeper than the root. I end up with a situtation where I'm always missing a directory level in my location.</p>
  <p>Of course I could hard code in the location of my JS, CSS, and Media for a given website by just adding <code>location /js {root /directory/files/website;}</code> to my config file, but this solution doesn't scale across multiple hosted pages at different locations website, website2, website3, etc.</p>
  <p>Am I crazy? Have other people encountered this scenario? Am I using Nginx wrong? How do I get around this? If my browser knows which directory a page was requested from, why are relative links still treated as being relative to the server root, instead of the directory the page came from???</p>