Nginx转发SVN

在Linux中安装好subversion服务器后,使用的是svn协议,要让他使用http/https协议可以借助Nginx+httpd。

一、安装配置svn服务

前面有讲过,这里就不再复述了CentOS中svn服务器安装与使用

假设有svn仓库:

  • test1: /home/svn/test1
  • test2: /home/svn/test2
  • 两仓库的账号和权限认证文件都为:/home/svn/passwd/home/svn/authz
  • svn以/home/svn为根目录启动

二、安装httpd

使用Apache HTTP服务将svn协议转成http协议,需要安装httpdmod_dav_svn

yum install httpd mod_dav_svn -y

三、配置httpd

添svn.conf配置

增加配置文件/etc/httpd/conf.d/svn.conf

#创建并编辑配置文件
vim /etc/httpd/conf.d/svn.conf

# 添加内容
<Location />
        DAV svn
        SVNParentPath /home/svn/
        AuthType Basic
        AuthName "Authorization Realm"
        AuthUserFile /home/svn/passwdfile
        AuthzSVNAccessFile /home/svn/authz
        Require valid-user
        SVNAdvertiseV2Protocol Off
</Location>
  • SVNParentPath 多仓库的根目录,如果是单仓库配置用SVNPath
  • AuthUserFile 账号密码文件,这里后面需要新建一个,这密码是加密的与svn服务配置的账号密码一样就可以了
  • AuthzSVNAccessFile 权限设置文件,与svn服务使用同一个文件

配置http用户名密码认证文件 /home/svn/passwdfile

htpasswd -cb /home/svn/passwdfile user password

用htpasswd 创建账号(user)、密码(password),这里的账号密码需要和svn服务器中/home/svn/passwd文件的一致

配置/etc/httpd/conf/httpd.conf

vim /etc/httpd/conf/httpd.conf
# 这里需要配置Listen和ServerName
Listen = 8369
ServerName = 127.0.0.1:8369

设置防火墙和Selinux

# 因为httpd的8369端口不对外开放,所以可以不开放这个端口。如果要放开可以用
firewall-cmd --zone=public --remove-port=8369/tcp --permanent
firewall-cmd --reload

# 设置selinux开放httpd
semanage port -a -t http_port_t -p tcp 8369
semanage permissive -a httpd_t

四、重启httpd

systemctl restart httpd
systemctl enable httpd

五、配置nginx

/etc/nginx/nginx.conf配置中添加svn转发

# http转发
server {
        listen          80;
        server_name     svn.zngw.icu;  # svn的域名

        location = /favicon.ico {
                log_not_found   off;
        }

        location / {
                proxy_pass http://localhost:8369;

                # header 开始
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   Cookie $http_cookie;
                # header 结束

                # 单文件大小
                client_max_body_size 5000M;
        }
}

# https转发
server {
    listen 443 ssl;
    server_name  svn.zngw.icu;
    #ssl on;
    ssl_certificate /etc/nginx/key/ svn.zngw.icu.crt;
    ssl_certificate_key /etc/nginx/key/ svn.zngw.icu.key;
    ssl_session_timeout  5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;     #指定SSL服务器端支持的协议版本
    ssl_ciphers  HIGH:!aNULL:!MD5;
    #ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;    #指定加密算法
    ssl_prefer_server_ciphers   on;    #在使用SSLv3和TLS协议时指定服务器的加密算法要优先于客户端的加密算法

    # rewrite ^ http://$http_host$request_uri? permanent;
    location / {
                proxy_pass http://localhost:8369;

                # header 开始
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   Cookie $http_cookie;
                # header 结束

                # 单文件大小
                client_max_body_size 5000M;
    }
}

重新加载Nginx配置

nginx -s reload

设置权限

chown apache:apache -R /home/svn

测试

在流量器中直接输入 http://svn.zngw.icu/test1 可以弹出账号登录页面,登录成功可以访问网页版的svn。用svn客户端checkout http://svn.zngw.icu/test1 就可以下载test1项目

0%