Can my /public directory be a symlink with rails 3 + passenger 3 + nginx 0.8?
Asked Answered
A

3

6

I'm putting together a rails deployment where the public directory is a symlink to another directory on the system. This is with passenger 3 on nginx .8. It does't seem to like that setup. Nginx always follows symlinks by default, so AFAIK it's not a matter of doing the equivalent of Apache's +FollowSymLinks.

update

Looks like this is covered here: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#application_detection

Note that Phusion Passenger for Nginx does not resolve any symlinks in the root path. So for example, suppose that your root points to /home/www/example.com, which in turn is a symlink to /webapps/example.com/public. Phusion Passenger for Nginx will check for /home/www/config/environment.rb, not /webapps/example.com/config/environment.rb. This file of course doesn’t exist, and as a result Phusion Passenger will not activate itself for this virtual host, and you’ll most likely see some output generated by the Nginx default directory handler such as a Forbidden error message.

Detection of Rack applications happens through the same mechanism, exception that Phusion Passenger will look for config.ru instead of config/environment.rb.

So I wonder if some proper symlinking of config.ru might do the trick.

Arnettearney answered 19/12, 2010 at 21:58 Comment(2)
Define "It does't seem to like that setup." What you are trying to do should work.Manwell
I just added an update with some info from the documentation -- looks like it's not supported.Arnettearney
S
3

I think it is not possible to use a symlinked public directory. The only workaround I can imagine is to symlink any file and directory inside of the public dir.

# public folder: /data/public
# app folder: /webapp/
mkdir -p /webapp/public && ln -sf /data/public/* /webapp/public/

For every new file or directory in /data/public you have to run this command again.

Stockade answered 10/1, 2011 at 14:46 Comment(1)
Even though the other answer was more valuable to me, I'm marking this one as "correct" because it's sort of a more literal correct answer to the question I asked (and also that way I can give "honorable mention" :) )Arnettearney
M
10

Can't you use the following:

mount --bind /original_path /your_ngnix_root_path

instead of using symlinks? For ngnix it would be a usual directory, why it will point to another directory as you wanted it to be.

Maloy answered 14/1, 2011 at 10:5 Comment(6)
This works! And it's something I didn't know about at all. I wonder if there are any side effects to be wary of… seems like something that low level could end up being too good to be true. Any more thoughts on this?Arnettearney
mount --bind works on the same level as simple mount of hdd or other storage media, so it is transparent to user level and no side effects should raise in your case.Maloy
I noticed that I can't do a rm -rf on a dir with such a mount point, I have to unmount it first. So it does add that step to my deploy recipe (which is fine).Arnettearney
Do not use rm -rf <target_dir> - the directory is busy being mountpoint. Use rm -rf <target_dir>/* to delete everything inside the directory.Maloy
What about loosing the 'mount' after rebooting?Ricky
Just put it in /etc/rc.local or something similar. It is like "How about starting the server after reboot?" or "How about mounting network disks after reboot?" - it is part of your server configuration, do it in init scripts!Maloy
S
3

I think it is not possible to use a symlinked public directory. The only workaround I can imagine is to symlink any file and directory inside of the public dir.

# public folder: /data/public
# app folder: /webapp/
mkdir -p /webapp/public && ln -sf /data/public/* /webapp/public/

For every new file or directory in /data/public you have to run this command again.

Stockade answered 10/1, 2011 at 14:46 Comment(1)
Even though the other answer was more valuable to me, I'm marking this one as "correct" because it's sort of a more literal correct answer to the question I asked (and also that way I can give "honorable mention" :) )Arnettearney
G
0

I was able to do this with the guide linked below.

  1. Create your rails app in /var/www/html
  2. Delete default.
  3. Edit the /etc/nginx/nginx.conf file
  4. symlink to sites-enabled
  5. Restart nginx

How to Deploy Ruby on Rails with Passenger and Nginx on Ubuntu 16.04

Glede answered 10/3, 2019 at 0:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.