diff --git a/modules/gerrit/files/replication.config b/modules/gerrit/files/replication.config
index ebb5978f2f..33786eaddc 100644
--- a/modules/gerrit/files/replication.config
+++ b/modules/gerrit/files/replication.config
@@ -3,3 +3,9 @@
[remote "github"]
url = git@github.com:${name}.git
+
+[remote "local"]
+url = file:///var/lib/git/${name}.git
+replicationDelay = 0
+threads = 4
+mirror = true
diff --git a/modules/gerrit/templates/gerrit.vhost.erb b/modules/gerrit/templates/gerrit.vhost.erb
index 363898437b..4b647802b7 100644
--- a/modules/gerrit/templates/gerrit.vhost.erb
+++ b/modules/gerrit/templates/gerrit.vhost.erb
@@ -43,13 +43,22 @@
RewriteEngine on
RewriteCond %{HTTP_HOST} !<%= virtual_hostname %>
RewriteRule ^.*$ <%= canonicalweburl %>
+ RewriteCond %{REQUEST_URI} !^/p/
+ RewriteRule ^/(.*)$ http://localhost:8081/$1 [P]
- ProxyPassReverse / http://localhost:8081/
-
- Order allow,deny
- Allow from all
- ProxyPass http://localhost:8081/ retry=0
-
+ ProxyPassReverse / http://localhost:8081/
+
+ SetEnv GIT_PROJECT_ROOT /var/lib/git/
+ SetEnv GIT_HTTP_EXPORT_ALL
+
+ AliasMatch ^/p/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/lib/git/$1
+ AliasMatch ^/p/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/lib/git/$1
+ ScriptAlias /p/ /usr/lib/git-core/git-http-backend/
+
+
+ Order allow,deny
+ Allow from all
+