Ubuntu18.04 Server安装Nginx+Git服务和独立的svn服务

安装Nginx+Git

须要安装的包有 nginx, fcgiwrap, git. 其中git在Ubuntu18.04 Server安装时已经默认安装了. 须要安装的是前两个nginx

而fcgiwrap是在 universe 区域里面(找一个包时若是不肯定是在那个区域, 能够在 https://packages.ubuntu.com/ 上面先查一下git

默认的Ubuntu18.04 Server的 /etc/apt/source.list 内容是这样的ubuntu

deb http://cn.archive.ubuntu.com/ubuntu bionic main 
deb http://cn.archive.ubuntu.com/ubuntu bionic-security main 
deb http://cn.archive.ubuntu.com/ubuntu bionic-updates main 

须要在main后面加上universe, 不然apt install 会找不到 fcgiwrapsocket

deb http://cn.archive.ubuntu.com/ubuntu bionic main universe
deb http://cn.archive.ubuntu.com/ubuntu bionic-security main universe
deb http://cn.archive.ubuntu.com/ubuntu bionic-updates main universe

而后执行 sudo apt update 后, 就能够经过 sudo apt install fcgiwrap安装了.ionic

建立Git工做目录

这里将git工做目录放置到 /var/www/git , 将目录权限设置为 www-data (和nginx的worker一致)svn

cd /var/www/
sudo mkdir git
sudo chown -R www-data:www-data git/
cd git/
sudo mkdir sandbox.git
cd sandbox.git/
sudo git --bare init
sudo git update-server-info
sudo chown -R www-data:www-data .

在sandbox.git目录下, 设置目录和文件权限测试

# 设置目录为755
sudo find . -type d -exec chmod 755 {} +
# 设置文件为644
sudo find . -type f -exec chmod 644 {} +

 

配置Nginx

修改nginx默认的配置文件spa

# backup the default config
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default-bak
# Open the file for editing with the command:
sudo vi /etc/nginx/sites-available/default

在默认的 location / {} 后面, 增长下面的内容unix

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
#增长的内容
    location ~ (/.*) {
        client_max_body_size 0; # Git pushes can be massive, prevent suddenly cut the connection
        auth_basic "Git Login"; # For displaying
        auth_basic_user_file "/var/www/git/htpasswd";
        include /etc/nginx/fastcgi_params; # Include the default fastcgi configs
        fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; # Tells fastcgi to pass the request to the git http backend executable
        fastcgi_param GIT_HTTP_EXPORT_ALL "";
        fastcgi_param GIT_PROJECT_ROOT /var/www/git; # The location of all of your git repositories.
        fastcgi_param REMOTE_USER $remote_user;
        fastcgi_param PATH_INFO $1; # Takes the capture group from our location directive and gives git that.
        fastcgi_pass  unix:/var/run/fcgiwrap.socket; # Pass the request to fastcgi
    }

以上的配置, location ~ (/.*) 这个正则匹配会命中全部的访问, 并将括号内的值赋为 PATH_INFO, 这时候访问git的URL为 http://server_ip/sandbox.git .rest

若是想将访问限制在一个二级目录下, 假设为git目录, 那么须要修改上面的location为

location ~ /git(/.*)

这时候访问的URL就是 http://server_ip/git/sandbox.git

 

建立密码文件

能够经过 htpasswd -c /var/www/git/htpasswd milton 来建立, 也能够经过 openssl passwd -apr1 生成口令来手动建立

而后重启nginx

sudo systemctl restart/reload nginx

这时候就能够经过git客户端链接测试了.

 

添加新Git仓库

sudo mkdir sandbox.git
cd sandbox.git/

sudo git --bare init
sudo git update-server-info
sudo chown -R www-data:www-data .
# 设置目录为755
sudo find . -type d -exec chmod 755 {} +
# 设置文件为644
sudo find . -type f -exec chmod 644 {} +

 

安装SVN服务

安装subversion

sudo apt install subversion

建立svn的仓库目录

cd /var/www/
sudo mkdir svn

在这个目录下建立两个文件 passwd 和 auth, 内容分别以下, 做为共用的用户管理, 将在各个svn仓库的配置中引用这两个文件

/var/www/svn$ more passwd[users]
harry = 111111
sally = 123123


/var/www/svn$ more authz 
[aliases]

[groups]
admin = harry,sally

[/]
@admin = rw

建立一个svn仓库

cd svn/
sudo svnadmin create sandbox

编辑 sandbox/conf/svnserve.conf, 须要修改三处

[general]
anon-access = none
password-db = ../../passwd
authz-db = ../../authz

启动svn服务

# 去掉 --foreground就是后台运行
svnserve -d --foreground -r /var/www/svn/

在客户端就能够经过 svn co svn://server_ip/sandbox/ 来checkout项目了

相关文章
相关标签/搜索