Content
Reverse proxy and link generation
Added by Taras Zakharko over 11 years ago
Dear all,
I am currently trying to set up OpenProject on our server. For a number of reasons, I have my OpenProject+Passenger installation on a virtual linux machine (Debian). The VM is connected to a host-only virtual network and everything works wonderfully when the the website is accessed directly from the host. Now, to make it accessible to other clients, I am using a apache reverse proxy, something like this:
ProxyPass /projects http://projectsvm
ProxyPassReverse /projects http://projectsvm
Where projectsvm is the server-local virtual IP of the VM.
Now, this works, but unfortunately, OpenProject does not seem to be ok with the fact that is hosted via /projects. E.g. the links it generates are something like ‘server/login’ instead of ‘server/projects/login’. I tried fiddling around with rails_relative_url_root, but his only changes the links generated for the assets. Those also work in a weird way, e.g. /projects/assets/application-142f200494da18550f6a1573be06405b.js is accessed without any problems, but the similar link for the css does not work. At the same time, other generated links (e.g. for login window etc.) again lack the prefix.
I am very new to server configuration so its all quite confusing. I guess what I am looking for is a way to tell Passenger or OpenProject that my installation is accessible via the prefix /projects so that all links are generated correctly. Is there a way to do this?
Thank you!
Replies (5)
Hello Taras,
I must admit that I’m not sure about the following myself but as your problem sounds pretty much like subdirectory deployment it might be worth a try: Additionally to changing the
rails_relative_url_rootI find the following in the virtual host file:You find more detailed information in the passenger documentation about Deploying to a sub URI.
I hope this information helps?
Kind regards,
Hagen
Hi Hagen,
thank you for your answer! Unfortunately, I am not deploying Passenger via Apache - I am using the Standalone version in a virtual machine and then redirecting my main Apache server to this machine. You can think about it as having a dedicated machine only for OpenProject (running Passenger Standalone) behind a firewall and redirecting my main webserver to this box via a forward/reverse proxy.
The rails_relative_url_root works quite well for links OpenProject generates to find assets, but its not added to the website links like ‘login’, ‘projects’ etc. Unfortinately, I am a total noob when it comes to Ruby and Ruby on Rails. I think there is a way to modify routes.rb to add the prefix to every link (hard-coding it would be perfectly fine), but I have no idea how to go about this…
Alternatively, I can of course install Apache within my VM and try to work from there, but that would be a waste, I believe (essentially, I’ll be running 3 web servers behind each other).
Best,
Taras
Hi Taras,
there is another option, though it isn’t recommended: You can scope the routes (see the second bullet on the page linked) in
config/routes.rb.This is not a recommended approach because
But it might work.
Kind regards,
Hagen
Hi Hagen,
I just managed to fix my problems by using Thin instead of Passenger. It has this neat ‘—prefix’ option which does exactly what I wanted. Its strange that Passenger does not seem to support this…
Thank you for your help!
— Taras
Hi,
I had a similar problem: OpenProject running inside a Docker container using Passenger and Nginx, which I wanted to deploy publicly via Apache at a subdir URI (using SSL). Here is what I did:
configuration.ymland setrails_relative_url_rootto"/subdir"./home/app/openproject, this is my configuration file:server { listen 443 ssl; server_name localhost; ssl_certificate /etc/ssl/certs/openproject.crt; ssl_certificate_key /etc/ssl/private/openproject.key; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers RC4:HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; root /home/app/main; # Unrelated site, may be omitted # Deploy OpenProject at /subdir location ~ ^/subdir(/.*|$) { alias /home/app/openproject/public$1; passenger_base_uri /subdir; passenger_app_root /home/app/openproject; passenger_document_root /home/app/openproject/public; passenger_enabled on; passenger_user app; } passenger_enabled on; passenger_user app; passenger_ruby /usr/bin/ruby2.1; }Note that it is important to repeat
passenger_enabled oninside thelocationdirective.RAILS_ENV=production bundle exec rake assets:precompileagain.After restarting Nginx, OpenProject should be available and working at
https://localhost:3000/subdir. This may not be required, but since I’m using HTTPS, in Administration > Settings > General, I’ve set Protocol to HTTPS.Then, configure Apache on the host to act as a reverse proxy:
<VirtualHost _default_:443> SSLProxyEngine on ProxyRequests Off ProxyPass /subdir https://127.0.0.1:3000/subdir <Proxy https://127.0.0.1:3000/subdir/*> Order deny,allow Allow from all </Proxy> <Location /subdir> ProxyPassReverse https://127.0.0.1:3000/subdir </Location> # Rest of virtual host configuration… </VirtualHost>Now, OpenProject is available and working at
https://mydomain.com/subdir.Having the public interface and the internal site use the same protocol (HTTPS in my case) and the same path (
/subdir) was critical to have this work seamlessly.Hope this helps!