Jump to content
MDDHosting Forums

Apache and Symlinks (related to Ruby on Rails)


Scott
 Share

Recommended Posts

So, I've been fighting with this for a few days now and am getting no where.

I have a RoR app located at ~/etc/rails_apps/new_site/current. In my beta subdomain (~/public_html/beta) I have a .htaccess which I will post below that rewrites requests to that domain for RoR.

 

.htaccess

Options -Indexes +FollowSymLinks
RewriteEngine on

RewriteCond %{DOCUMENT_ROOT}/public/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /public/system/maintenance.html [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)?$ "http://127.0.0.1:12003/$1" [P,QSA,L]

 

The problem is in the maintenance.html section. It should see if that file exists, and if it does, redirect all requests to that page. The public dir is a symlink into the rails app. For some reason, it never seems to think the maintenance.html page exists, but attempts to access it work just fine (See http://beta.thecliplady.com/system/maintenance.html). I've tried rewriting the conditions for it with hardcoded paths (/home/my_user/public_html ...), the URL that actually works, and everything I can think of.

 

The only thing that worked was moving the entire rails app into the document root for the web server, but that is a major security issue since the raw ruby code could be access by anyone with a little knowledge of ruby on rails.

 

Does anyone have any ideas what could be happening or how to fix this?

Link to comment
Share on other sites

I'm not really familiar with Ruby on Rails, if you can give me a basic explanation of where the application is stored, where you want to actually access the script from, and how you're trying to go about doing it I can try to help.

 

Maybe you can move the application into the public_directory and then simply use some smart rewriting to prevent direct access to the source?

Link to comment
Share on other sites

I'm not really familiar with Ruby on Rails, if you can give me a basic explanation of where the application is stored, where you want to actually access the script from, and how you're trying to go about doing it I can try to help.

 

Maybe you can move the application into the public_directory and then simply use some smart rewriting to prevent direct access to the source?

 

By default, cpanel stores rails apps at ~/etc/rails_apps/NAME_OF_APP, so my app is running from ~/etc/rails_apps/new_site/curent. I had dabbled with hosting it inside of public_html, but then the rerwrite code needed to make cached and static files work exposed the source. (It's a lose lose either way).

 

(Rails is hidden off on another port that is blocked by the firewalls, so you use apache to mod_rewrite the requests to mongrel, the rails server. But, since a lot of what the website serves is .js, .css, or various images, it makes sense to have that hosted by apache and not mongrel (which is single-threaded, and thus handles one request at a time))

 

What I am thinking about now is trying to use a different docroot for the subdomain. ~/etc/rails_apps/new_site/current/public. Unfortunately, cpanel seems to want everything under public_html, so it always prepends that to the path when I try to set it up in subdomain manager in cpanel.

 

The guys at pragmatic programmers have a great book on deploying rails apps. They cover everything from shared hosts, to dedicated servers and the crazy proxying / clustering things I will never need. But in the end, it was a great read on how to do rails deployments "right," and still be considerate of resource usage and the like.

 

http://www.pragprog.com/titles/fr_deploy/d...ls-applications

 

PS: Is apache configured with any kind of global "Options -FollowIndexes" ??

Link to comment
Share on other sites

What I am thinking about now is trying to use a different docroot for the subdomain. ~/etc/rails_apps/new_site/current/public. Unfortunately, cpanel seems to want everything under public_html, so it always prepends that to the path when I try to set it up in subdomain manager in cpanel.
I can modify this behavior temporarily for you so that you can set up what you need if you wish, just submit a ticket :)

 

The guys at pragmatic programmers have a great book on deploying rails apps. They cover everything from shared hosts, to dedicated servers and the crazy proxying / clustering things I will never need. But in the end, it was a great read on how to do rails deployments "right," and still be considerate of resource usage and the like.
Nice :) I was thinking of setting up a LSWS Internal Proxy for you that would proxy requests over to Mongrel internally for you without needing mod_rewrite but it would be my first time doing it so we would need to do some trial and error and I can't promise 100% it will do what you need but I think it would :)

 

As for running RoR by cPanel/Apache - if you get me some information on that maybe we can help :)

 

PS: Is apache configured with any kind of global "Options -FollowIndexes" ??

You mean FollowSymlinks? Not that I am aware of but putting +FollowSymlinks in a .htaccess over-rides whatever is global.

 

Some quick testing would reveal the default but I'm not sure off the top of my head.

Link to comment
Share on other sites

I can modify this behavior temporarily for you so that you can set up what you need if you wish, just submit a ticket :)

Will do. I'm headed off to work tho, so I expect it will be a few hours.

 

Nice :) I was thinking of setting up a LSWS Internal Proxy for you that would proxy requests over to Mongrel internally for you without needing mod_rewrite but it would be my first time doing it so we would need to do some trial and error and I can't promise 100% it will do what you need but I think it would :)

I typically see the proxying being done more with mongrel_cluster, but I'm game to try. The backups on your servers are great, so there isn't really anything to lose :)

 

As for running RoR by cPanel/Apache - if you get me some information on that maybe we can help :)

 

I don't see a lot of resources online specific to cpanel, but at its core its really just install a skel rails app, and then writing a mongrel config to start mongrel with. The PragProg book I posted below would explain everything you need to know. Plus the PDF ebook version is a steal at like $24.00.

 

When I get a chance, I'll try to do a quick write up that covers all of the "parts" to rails on cpanel, point out where they are located, how to use them, etc.

 

You mean FollowSymlinks? Not that I am aware of but putting +FollowSymlinks in a .htaccess over-rides whatever is global.

Yup, that was what I meant. I put it in .htaccess and apache was still being weird with detecting of my maintenance.html actually existed.

Link to comment
Share on other sites

Will do. I'm headed off to work tho, so I expect it will be a few hours.
No problem :)

 

When I get a chance, I'll try to do a quick write up that covers all of the "parts" to rails on cpanel, point out where they are located, how to use them, etc.
Go for it and I'll put it somewhere good on the forums as a guide to others and it will probably end up in our internal wiki as well :)

 

 

Yup, that was what I meant. I put it in .htaccess and apache was still being weird with detecting of my maintenance.html actually existed.

Well if you can give the exact steps of how to replicate this I can pass this on to George and see what he says about it.

Link to comment
Share on other sites

Well if you can give the exact steps of how to replicate this I can pass this on to George and see what he says about it.

 

Step 1: Create a subdomain in cpanel... I called mine "beta" but I doubt that matters.

 

Step 2: Create a rails app in cpanel. I used an app name of new_site located in ~/etc/rails_apps/new_site/current

 

Step 3: Open the rails app with ssh, browse to public and mkdir system, then touch maintenance.html. Edit it with some dummy text so we can see it in a web browser when we try to visit it later.

 

Step 4: Edit the .htaccess in ~/public_html/beta (or whatever subdomain you setup) to reflect the .htaccess I posted earlier.

 

Step 5: using ssh, cd to ~/public_html/beta and run this command:

ln -nfs ~/etc/rails_apps/new_site/current/public

 

Step 6: visiting beta.yourdomain.com/public/system/maintenance.html should load the maintenance.html file you created earlier. Visiting any other URL on that domain should also show the contents of maintenance.html.

Link to comment
Share on other sites

It's worth mentioning that we tracked down the cause of this error and the suexec (http://redmine.lighttpd.net/projects/lighttpd/wiki/SuEXEC) features of LSWS/Apache block content outside of your public_html from being found or used by the web server. Thus you can't have your docroot outside of public_html for rails, nor can you use any kind of symlink magic to get to the rails files either.

 

I'll post more when I have another deployment strategy that should work better on cpanel systems.

Link to comment
Share on other sites

We did learn quite a bit however about Rails+cPanel+Apache+LSWS :)

 

I also learned that restarting my mongrel for beta.thecliplady.com somehow made beta4.thecliplady.com work correctly... I think. Tho I have kind of lost track of what is where atm, but I think beta4 is LSWS proxy.

 

And I also learned that rails deployments give me headaches. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...