WebFaction
Community site: login faq

There is no reason to call the user Nginx or Passenger for any access to the public directory, but I am not sure how it can be setup since access to rails app and public directory share the root path.

I was able to get a chunk of the benefit by enabling asset hosting in Rails and setting up a symlink static app. This helps with css/js/graphic files since rails writes the asset host path in.

But it doesn't help with other files in public like cached pages, favicon, sitemap, etc. The user Nginx is smart enough to not pass those requests to Passenger, but ideally it should just be served from the server-wide Nginx. Is this possible? I guess I could create a static app for every directory and file in public, but that seems pretty silly.

asked 16 May '11, 19:04

Bc25
547
accept rate: 0%


Currently, this is simply not possible on the current system. This is because URL paths are parsed entirely in URL space and don't "connect" with the filesystem until it's been determined which app (based on the URL space) should be handling that request. So, it's necessary to specify to the server Nginx which application should handle a request based on the URL, which means that giving the front-end Nginx a url-based hint (like "all files coming in on path /static") for it to know where to go with that request.

However, we are looking into making it possible to host individual files statically as an symbolic link application using the path to a file instead of a directory, although we can't promise if and when it will be available. If this is implemented, then you could write a script (using the API) to do this for every file in your "public" directory that doesn't work in the normal method. As you said, this isn't ideal, but at least it will be possible once this feature has been implemented.

That said, there is still a work-around that can be used in your case. For example, let's say that you have a file "foo.txt" that may be served from any arbitrary URL Path. One thing you could to is to create a separate Static/CGI/PHP application with a .htaccess file and rewrite rules to re-map, say, ^.*/foo.txt$ to another URL path which is being served by Nginx, like /static/foo.txt . This work-around will be more useful if the files to be served are relatively "heavy" and there is a lot to be gained, since it does introduce another request layer for every request.

Hope that helps!

permanent link

answered 16 May '11, 19:40

ryans ♦♦
5.0k93360
accept rate: 43%

edited 16 May '11, 19:58

The Static/CGI/PHP apps are served by Apache, right? So it'll go Nginx->Apache->rewrite to server Nginx. Wouldn't Nginx -> User Nginx as it works now be faster?

Am I correct in guessing that the Static/CGI/PHP solution is what would be required to make a custom page caching path work with rails? E.g. setting page caching to public/static and then using the Static/CGI/PHP app to rewrite the requests?

Thanks for your help.

(16 May '11, 21:34) Bc25

Yes, this is correct. It's not a very good workaround in general.

However, if you had a relatively small site but you were trying to serve, say, a 1 GB static file to several clients, this approach would make a lot of sense, offloading the entire burden to the server Nginx at the expense of only a couple of extra requests.

(16 May '11, 21:51) ryans ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×186
×125
×108

question asked: 16 May '11, 19:04

question was seen: 5,441 times

last updated: 16 May '11, 21:51

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM