Broken CSS/images/JS in sub-URI deployment

First of all, to the authors, thanks for writing sequenceserver.

I’ve installed sequenceserver with and without Passenger - it works perfectly fine without Passenger through port 4567, but I’m having troubles getting it to work on Apache via Passenger.

The app loads up fine when I deploy it at the sub-URI foo.com/blast, but the CSS, images and JS files are not loaded correctly. An inspection of the HTML source code reveals that the static content is linked wrongly - for instance, the minified CSS of the website is linking to foo.com/css/sequenceserver.min.css (which is a 404 dead link), whereas the correct link should be foo.com/blast/css/sequenceserver.min.css (which contains plaintext when manually accessed via the URL bar of my browser). My deployment server runs Debian Stable, Apache 2.2, Ruby 1.9.1.

Strangely, I do not have the same problem on my test server - however, my test server runs Debian Unstable, Apache 2.4, and Ruby 2.1.0, so it might be that Apache 2.4 has saner behaviour compared to 2.2.

There’s a similar description of what I’m experiencing on the Passenger website itself: https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#sub_uri_deployment_uri_fix, but as I’m not well-versed in Ruby nor Apache, I do not know what I need to fix for the links to work properly.

If it’s of any help, the relevant bits of my Apache .conf file reads:

Options Indexes FollowSymLinks Includes AllowOverride All Options -MultiViews #Require all granted

Alias /blast /usr/lib/ruby/gems/1.9.1/gems/sequenceserver-1.0.2/public
<Location /blast>
PassengerBaseURI /blast
PassengerAppRoot /usr/lib/ruby/gems/1.9.1/gems/sequenceserver-1.0.2

<Directory /usr/lib/ruby/gems/1.9.1/gems/sequenceserver-1.0.2/public>
Allow from all
Options -MultiViews
#Require all granted

(“Require all granted” is commented out because my deploy server is not running Apache 2.4. I didn’t use RackBaseURI as suggested on the sequenceserver main site as it’s been deprecated https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#_railsbaseuri_and_rackbaseuri ).

I appreciate any help/tips, thanks in advance!

SequenceServer uses relative URLs. For the setup to work correctly your webserver needs to treat foo.com/blast as foo.com/blast/. Perhaps that’s the default behavior of Apache 2.4. I’m not sure how to accomplish the same with Apache 2.2. You could setup a redirect … or maybe just changing /blast to /blast/ in your Apache config will do it.

– Priyam

… I feel like an idiot now - without changing anything in the .conf file, foo.com/blast/ (<-- with the slash) works! Adding slashes to the conf file did not fix the problem if one navigated to foo.com/blast; I still had to manually navigate to /blast/ for it to work properly.

On my Apache 2.4 test server, typing in footest.com/blast automatically redirects to footest.com/blast/, which was why I never noticed the subtle problem. I’m not an experienced webdev so I’m not sure why this happens automatically (in the absence of any RewriteCond on my test server too).

I’ll probably just set up a RewriteCond of some sorts to automatically change /blast to /blast/ on the deploy server. Thanks Priyam!

Yi Jin Liew:

Can I have your redirect configuration in the Apache configuration file?

I was having a similar problem to you. It is a bit weird, as on: Ubuntu Utopic with Apache 2.4.10, Ruby 2.1.2 and Gems 2.4.8 it works perfectly well… However, on our lab’s website server: Ubuntu Trusty, Apache 2.4.7, Ruby 1.9.1 and Gems 2.4.5 I get the 404 error of not being able to download sequences or show fastas. I should say I also have WordPress enabled on the lab server and this adds all sorts of rewrite rules to the .htaccess file.

This is entirely to do with the trailing slash missing from the server URL. If I go to http://richardslab.ex.ac.uk/blastocladiella it won’t work but if I go to http://richardslab.ex.ac.uk**/** ← trailing slash → it works fine.

Supposedly in Apache 2.2 and 2.4 DirectorySlash On is enabled by default, and I had no luck including this in apache2.conf, 000-default.conf, or .htaccess

But the way I did get it to work is by adding these extra rewrite rules to the server’s .htaccess file.

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !index.php RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://your-server.com/$1/ [L,R=301]

The first line stops any file (e.g. index.html) from being rewritten, the second line specifically tells the server not to rewrite rules with index.php (all of wordpress), the third line finds any URL without a trailing slash and the fourth line rewrites any sub-domain URL to include a trailing slash.

If you haven’t got any rewrite rules in your .htaccess already, you will need to add these two lines before the four above.

RewriteEngine On RewriteBase /

Hope that helps anyone else who is having issues!

Guy