I am trying different ways of deploying Rails app (redmine, to be specific) with nginx and Passenger. Let’s say that I have it installed in /var/local/railapps/redmine-1.1.
When I deploy as sub-uri, I can make the soft link just to public folder:
sudo ln -s /var/local/railapps/redmine-1.1/public /var/www/rails/redmine
and add to server block in nginx.conf:
root /var/www/rails;
passenger_enabled on;
passenger_base_uri /redmine;
With this, redmine can access folders on the same level as public, for example, /var/local/railapps/redmine-1.1/config.
On the other hand, Passenger does not resolve soft links when it is installed to a host root (according to this guide):
sudo ln -s /var/local/railapps/redmine-1.1/public /var/www/rails/redmine
root /var/www/rails/redmine;
passenger_enabled on;
I am getting the error from Passenger: No such file or directory - config/environment.rb in root /var/www/rails, which means that it tries to get relative paths not from the link target, but from the link itself. If I make the link to the main redmine folder, the whole thing works:
sudo ln -s /var/local/railapps/redmine-1.1 /var/www/rails/redmine
root /var/www/rails/redmine/public;
passenger_enabled on;
So, the question is, why is Passenger able to resolve softlinks in “sub-uri” mode, but is not in “host root” mode? Are there some additional settings?
It does not do that in “host root mode” in order to support Capistrano-style deployment directories. This is documented in detail in this section of the documentation of the Apache version. The Apache version allows customizing the symlink resolving behavior (for backward compatibility reasons), while the Nginx version only supports one type of behavior.