Frage

Ich versuche, eine Sub-Domain-to-Repository Übersetzung in Apache einzurichten. Beispiel:

foobars.domain.com -> /server/svnrepos/foobars

Ich habe versucht, damit fertig werden mod_rewrite :

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com$ [NC]
RewriteRule ^/svn(.*) /svn/%2$1 [PT]

Dies verursacht jedoch Probleme bei der grundlegenden SVN-Operationen; ‚Kasse‘ verursacht diese hübsche Sache:

$ svn co http://foobars.domain.com/svn
svn: '/svn/foobars/!svn/vcc/default' path not found

Ich habe keine Einschränkungen in Bezug auf dem Server-Setup (meine Maschinen, os, etc). Gibt es eine Möglichkeit, diese Übersetzung von Apache behandelt zu bekommen? Ich habe bei Massen virtuelle Hosts gesucht, aber ich sehe keinen Weg, um das Konzept zu DAV Standorten zu erweitern (Ich wünschte, es ein VirtualSvnPath war ...). Die Art und Weise mod_dav_svn Kräfte Sie entweder 1) explizit Ihren SVN-Repo-Pfad definieren, oder 2) definieren die Eltern, ist sehr begrenzt.

Vielleicht ist die ‚SVNSpecialURI‘ kann von Nutzen sein, obwohl ich keine Dokumentation auf ihm finden können ...

Unter der Annahme, dass mein Ziel ist es, eine Sub-Domain zu einem SVNPath abzubilden, was sind meine Optionen?

Meine aktuelle conf als Referenz:

<VirtualHost *:80 *:443>
    ServerAdmin admin@domain.com
    DocumentRoot "/server/www"
    ServerName domain.com
    ServerAlias *.domain.com www.domain.com domain.com
    ErrorLog logs/domain-error_log
    CustomLog logs/domain-access_log common

    DirectorySlash Off

    RewriteLogLevel 9
    RewriteLog /server/log/apache-rewrite.log

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com$ [NC]
    RewriteRule ^/svn$ /svn/ [QSA]

    RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com$ [NC]
    RewriteRule ^/svn(.*) /svn/%2$1 [PT]

<Location /svn>
    DAV svn
    SVNParentPath /server/svn
</Location>

War es hilfreich?

Lösung

In the interest of Open Source (yay!), I'll post my solution. I found no built-in solution to my problem, so I spent a few hours on the mod_dav_svn.so sources and came up with this patch:

Index: subversion/mod_dav_svn/mod_dav_svn.c
===================================================================
--- subversion/mod_dav_svn/mod_dav_svn.c        (revision 1049733)
+++ subversion/mod_dav_svn/mod_dav_svn.c        (working copy)
@@ -426,9 +426,14 @@
dav_svn__get_fs_parent_path(request_rec *r)
 {
   dir_conf_t *conf;
+  char *tokens, *subdomain, *last_str;

   conf = ap_get_module_config(r->per_dir_config, &dav_svn_module);
-  return conf->fs_parent_path;
+
+  tokens = apr_pstrdup(r->pool, r->hostname);   // copy hostname
+  subdomain = apr_strtok(tokens, ".", &last_str);
+
+  return (const char *) apr_pstrcat(r->pool, conf->fs_parent_path, "/", subdomain, NULL);
 }

Essentially, this grabs the current hostname (from the pending request 'request_rec'), slices away the first token (subdomain), and concatenates that with the proper SVNParentPath (conf->fs_parent_path) and voila! Everything works as it should. Here's my server config (notice how simple it is now):

<VirtualHost *:80 *:443>
    ServerAdmin admin@domain.com
    DocumentRoot "/server/www"
    ServerName domain.com
    ServerAlias *.domain.com www.domain.com domain.com
    ErrorLog logs/domain-error_log
    CustomLog logs/domain-access_log common

    <Location /svn>
        DAV svn
        SVNParentPath /server/svn
        SVNListParentPath on
    </Location>
</VirtualHost>

Notes:

I hope that I used the apr_* functions correctly, if there are any caveats, I'd like some feedback :)

Tested on Centos with latest mod_dav_svn tree.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top