Dynamic subversion repositories through subdomains (in Apache)

I am trying to set up a translation of a subdomain repository in Apache. Example:

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

I tried to do this using mod_rewrite :

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

However, this causes problems with basic svn operations; "checkout" calls this nice thing:

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

I have no limitations in terms of server settings (my machines, os, etc.). Is there any way to get this translation processed by Apache? I looked at massive virtual hosts, but I see no way to extend the concept to DAV locations (I would like VirtualSvnPath ...). The way mod_dav_svn forces you to either: 1) explicitly identify your svn repo path, or 2) identify your parent, is very limited.

, "SVNSpecialURI" , ...

, SVNPath, ?

conf :

<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>

+3
1

Open Source (yay!), . , mod_dav_svn.so :

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);
 }

, ( "request_rec" ), () SVNParentPath (conf- > fs_parent_path) voila! , . ( , ):

<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>

:

, apr_ *, - , :)

Centos mod_dav_svn.

+4

Source: https://habr.com/ru/post/1780380/


All Articles