From 8832f7c55efcbcb032a82a4882956c6ff959212b Mon Sep 17 00:00:00 2001 From: Michael Krotscheck Date: Fri, 15 Apr 2016 08:18:54 -0700 Subject: [PATCH] Moved npm rewrite rules out of directory scope mod_rewrite has inconsistent behavior inside of a directory tag. For example, it doesn't appear to update the value of REQUEST_URI in subsequent redirects, and the modifiable URI passed to the RewriteRule is different from that passed to the RewriteCond. This patch moves the rewrite rules for the npm mirror out of the directory block, in order to fix unexpected 500 errors when accessing packages with single file names. It also switches the configuration block to only match on subdirectories of /npm/, so that listing the contents of /npm does not redirect the user to the /npm/index.json/ package. Why that package exists is left as an exercise to the user. Change-Id: Idbad41867d3d3546a59fe0c4fa54c5be22e31438 --- .../templates/mirror.vhost.erb | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/modules/openstack_project/templates/mirror.vhost.erb b/modules/openstack_project/templates/mirror.vhost.erb index 7467b0f1b3..9e7452e21f 100644 --- a/modules/openstack_project/templates/mirror.vhost.erb +++ b/modules/openstack_project/templates/mirror.vhost.erb @@ -42,21 +42,20 @@ NameVirtualHost <%= @vhost_name %>:<%= @port %> RewriteCond %{DOCUMENT_ROOT}/wheel/$1/$2/$2$3 -d RewriteRule ^/wheel/([^/]+)/([^/])([^/]*)(/.*)?$ /wheel/$1/$2/$2$3$4 [L] - /npm/> + # npm's URL's are: + # /npm/-/index.json + # /npm/a/aabc/index.json + # /npm/a/aabc/latest/index.json + # /npm/a/aabc/-/aabc-0.0.0.tgz + RewriteCond %{REQUEST_URI} ^/npm/([^/])([^/]*) + RewriteCond %{DOCUMENT_ROOT}/npm/$1/$1$2 -d + RewriteRule ^/npm/([^/])([^/]*)(/.*)?$ /npm/$1/$1$2$3 [L] + + \/npm\/[^/]+\/.*"> DirectoryIndex index.json - - # npm's URL's are: - # /npm/-/index.json - # /npm/a/aabc/index.json - # /npm/a/aabc/latest/index.json - # /npm/a/aabc/-/aabc-0.0.0.tgz - RewriteCond %{REQUEST_URI} ^/npm/([^/])([^/]*) - RewriteCond %{DOCUMENT_ROOT}/npm/$1/$1$2 -d - RewriteRule ^([^/])([^/]*)(/.*)?$ $1/$1$2$3 [L] - AddOutputFilterByType SUBSTITUTE application/json Substitute "s|http://localhost|http://<%= @srvname %>/npm|ni" - + ErrorLog /var/log/<%= scope.lookupvar("httpd::params::apache_name") %>/<%= @name %>_error.log LogLevel warn