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

二次信任 提交于 2019-11-27 18:36:49

问题


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.


回答1:


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.




回答2:


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:


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



来源:https://stackoverflow.com/questions/4485349/can-my-public-directory-be-a-symlink-with-rails-3-passenger-3-nginx-0-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!