因为我的服务器已经使用nginx, 但现在又需要在这个框架下搭建subversion 服务器. 在网上始终没找到在nginx 下直接配置subversion的办法. 于是曲线救国, 使用svn+apache+nginx 的方式. 大体思路是:
- nginx获取svn的请求
- nginx转发请求给apache
- apache获取这个请求并处理
服务器是centOS6.4, 64bits系统. ubuntu等系统应该主要差别是安装模块的那几步.
教程基于已经完成nginx配置的条件下. 如果是全新的服务器, 连nginx都没配置的, 可以有以下两种选择:
- 直接使用apache,不用nginx. (方法和本文有所出入)
- 先配置nginx,然后再参照本文. 配置nginx的方式可以参照另一片博文:
以下是具体怎么完成的, 教程尽量涉及细节,但可能还有所遗漏. 有什么问题可以留言哈.
STEP 1:安装apache subversion
1 2 3 4 5 |
yum install -y httpd yum install -y httpd-devel //用于开发Apache模块 yum install -y subversion yum install -y mod_dav_svn //Subversion与Apache之间的接口(通过它,Apache就可以访问版本库,可以让客户端也使用HTTP的扩展协议 WebDAV/DeltaV进行访问) yum install -y mod_auth_mysql //这一项用于用户身份验证,在网上有资料说貌似这个mod_auth_mysql没得配置访问权限的 只有用户设置,建议不装,用htpasswd就可以,在这里我没有装,我还是打算用htpasswd,可能下回会试试。 |
验证svn模块(mod_dav_svn)是否正确安装
1 |
ls /etc/httpd/modules | grep svn |
系统提示:
mod_authz_svn.so
mod_dav_svn.so
验证安装:
1 |
svn --version |
显示如下表明正确安装
=================================
svn,版本 1.4.2 (r22196)
编译于 Aug 10 2009,18:00:04
Copyright (C) 2000-2006 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
可使用以下的档案库存取 (RA) 模块:
* ra_dav : 通过WebDAV (DeltaV) 协议访问档案库的模块。
– handles 'http' scheme
– handles 'https' scheme
* ra_svn : 使用svn网络协议访问档案库的模块。
– handles 'svn' scheme
* ra_local : 访问本地磁盘的档案库模块。
– handles 'file' scheme
================================
STEP 2: 创建SVN库和项目
1 2 3 |
mkdir /svnRepo cd /svnRepo svnadmin create repo_name //创建项目 |
STEP 3:添加组及组员权限
1 2 3 |
groupadd subversion //创建一个叫subversion的组为拥有仓库所在的目录 usermod -G subversion -a apache //将自己和Apache 用户加入组成员中 more /etc/group | grep subversion |
系统提示:
subversion:x:500:apache
STEP 4:修改项目权限
1 2 3 |
chgrp -R subversion /svnRepo chown -R apache:subversion /svnRepo chmod -R 755 /svnRepo |
STEP 5: (VERY important) This step helps nginx forward all port 80 request about svn to 81 for apache.
Under the nginx config dir:
/usr/local/nginx/conf/vhost/
create a subversion.conf (any *.conf file)
Add these to the file.
1 2 3 4 5 6 7 8 |
server{ listen 80; server_name code.abc.me; location /svn { proxy_pass http://127.0.0.1:81/svn; } } |
#With this setting, the repo can be accessed by code.abc.me/svn
STEP 6: Using apache for subversion request
Edit:
/etc/httpd/conf.d/subversion.conf
Add these to the end:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<VirtualHost *:81> RequestHeader edit Destination ^https http early <Location /svn> DAV svn SVNPath /svnRepo/repo_name AuthzSVNAccessFile /svnRepo/repo_name/conf/authz AuthType Basic AuthName "ABC svn access" AuthUserFile /svnRepo/repo_name/conf/passwd Require valid-user </Location> </VirtualHost> |
ALSO Edit the file:
/etc/httpd/conf/httpd.conf
add this line to the file to let httpd listen to 81 port:
Listen 81
STEP 7: set up user permissions:
RUN:
1 2 3 4 |
htpasswd -c /svnRepo/repo_name/conf/passwd admin1 #(enter password) htpasswd /svnRepo/repo_name/conf/passwd admin2 #(enter password) |
Edit:
/svnRepo/repo_name/conf/svnserve.conf
make sure these lines are uncommented and correct:
1 2 3 4 5 |
anon-access = none auth-access = write password-db = passwd authz-db = authz realm = ABC overall repo |
Edit:
/svnRepo/repo_name/conf/authz
1 2 3 4 5 6 7 8 9 10 |
[groups] admin_team = admin1,admin2 proj1_team = staff1 [/] * = @admin_team = rw #[svn:/dir1/prj1] #@proj1_team = rw |
STEP 8: Start / Restart apache and nginx server
1 2 |
/etc/init.d/httpd restart (start) nginx -s reload |
STEP 9: Add project dir to repo
1 2 |
svn import /path/to/existed/projectdir file:////svnRepo/repo_name/ #This step could also be: svnadmin load xxx.dump |
#This step could also be: svnadmin load xxx.dump
STEP 10: Test in web browser:
http://code.abc.me/svn