Can my /public directory be a symlink with rails 3

2019-01-24 14:50发布

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.

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-24 15:05

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.

查看更多
何必那么认真
3楼-- · 2019-01-24 15:08

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.

查看更多
登录 后发表回答