部署GitWeb + Nginx 搭建微型代码库
MeteorCat安装组件:
1 2 3 4 5
| sudo apt install nginx nginx-extras
sudo apt install git gitweb fcgiwrap
|
默认创建 git 用户, 所有功能基于 git 用户操作
创建项目信息和权限:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| git config --global user.name 'MeteorCat' git config --global user.email '[email protected]'
sudo usermod -a -G git www-data
sudo mkdir /projects sudo chown -R git:git /projects
cd /projects sudo -u git git init --bare mix-game.git
cd mix-game.git sudo -u git git config --file config http.receivepack true
|
修改 GitWeb 配置内容:
1 2 3 4 5 6
| sudo vim /etc/gitweb.conf
|
启用 fcgiwrap, 让其启动并设置开机启动:
1 2
| sudo systemctl restart fcgiwrap.service sudo systemctl enable fcgiwrap.service
|
配置 Nginx 服务文件( /etc/nginx/conf.d/gitweb.conf ), 内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| server { listen 11111; server_name _;
location ~* ^.+\.(css|js|png|jpg|jpeg)$ { root /usr/share/gitweb; access_log off; expires 24h; }
location / { root /var/www; fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/gitweb.cgi; fastcgi_pass unix:/var/run/fcgiwrap.socket; include /etc/nginx/fastcgi_params; }
location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { root /projects; }
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { root /projects;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT $document_root;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $uri;
fastcgi_pass unix:/var/run/fcgiwrap.socket; } }
|
之后访问局域网就能看到挂起的服务对象:

如果想拉取代码直接常规 clone 即可:
1 2
| git clone http://192.168.1.111:11111/mix-game.git
|
