Git 是一个开源系统版本自动控制系统,被全世界不计其数的开发者应用,它适用于在源码等级追踪您的手机软件变更,它容许您追踪变更,将其修复到以前的环节并创建文档和目录的预留版本。
HTTP Git Server 是一个开源软件,它应用 Nginx 互联网服务器根据局域网络 (LAN) 为 Git 储存库给予服务项目,它比较简单且便于设定,所有人都能够从命令行页面管理方法它。
在本实例教程中,我将表述怎样在 Debian 11 上应用 Nginx 设定 HTTP Git 储存库服务器。
前提条件
- 运作 Debian 11 的服务器。
- 偏向您的服务器 IP 的合理网站域名。
- 在您的服务器上配备了 root 登陆密码。
组装 Nginx 和别的依靠
最先,您必须组装 Nginx Web 服务器和别的必要的程序包来设定 HTTP Git 服务器。您可以应用下列命令组装全部这种:
apt-get install nginx git fcgiwrap apache2-utils unzip -y
安装完全部程序包后,您可以再次下一步。
创建 Git 储存库
下面,您必须创建一个目录来储存 Git 存储库。使我们在 Nginx Web 根目录中创建一个名叫myrepo的目录:
mkdir /var/www/html/myrepo
下面,将目录更改成myrepo并且为客户创建另一个目录:
cd /var/www/html/myrepo
mkdir user1.git
下面,导航栏到客户目录并应用下列命令复位 Git 储存库:
cd user1.git
git --bare init
您将得到下列导出:
Initialized empty Git repository in /var/www/html/myrepo/user1.git/
下面,应用下列命令升级 Git 服务器信息内容:
git update-server-info
下面,应用下列命令变更 myrepo 的使用权并设定恰当的管理权限:
chown -R www-data:www-data /var/www/html/myrepo
chmod -R 755 /var/www/html/myrepo
下面,创建一个名叫 user1 的客户并密码设置:
htpasswd -c /var/www/html/myrepo/htpasswd user1
您可以设置密码,如下所示所显示:
New password:
Re-type new password:
Adding password for user user1
您可以应用下列命令查验您的登陆密码:
cat /var/www/html/myrepo/htpasswd
实例导出:
user1:$apr1$LoyCEkzA$Fjq5nBbLhBRdaxCQBBUQd1
配备 Nginx 以给予 Git 储存库
下面,您必须创建一个 Nginx 云服务器环境变量来为 Git 储存库给予服务项目。
nano /etc/nginx/conf.d/git.conf
加上下列几行:
server {
listen 80;
root /var/www/html/myrepo;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name git.yourdomain.com;
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;
auth_basic \"Git Login\";
auth_basic_user_file \"/var/www/html/myrepo/htpasswd\";
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 /var/www/html/myrepo;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $1;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
}
进行后储存并关掉文档,随后认证 Nginx 是不是存有一切拼写错误:
nginx -t
您将得到下列导出:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
最终,重启 Nginx 服务项目以运用变更:
systemctl restart nginx
您还能够采用下列命令查验 Nginx 情况:
systemctl status nginx
您将得到下列导出:
? nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-12-11 08:00:04 UTC; 2s ago
Docs: man:nginx(8)
Process: 144985 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 144986 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 144987 (nginx)
Tasks: 2 (limit: 2341)
Memory: 2.5M
CPU: 42ms
CGroup: /system.slice/nginx.service
??144987 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
??144988 nginx: worker process
Dec 11 08:00:04 debian11 systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 11 08:00:04 debian11 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Dec 11 08:00:04 debian11 systemd[1]: Started A high performance web server and a reverse proxy server.
从手机客户端联接到 Git 储存库
至此,Git HTTP服务器与Nginx构建进行。如今,是时候从用户端电子计算机联接它并完成检测了。
最先,应用下列命令在手机客户端计算机上安装 Git 包:
apt-get install git -y
下面,应用下列命令为您的新项目创建一个目录:
mkdir project
下面,导航栏到您的新项目目录并应用下列命令复位 Git:
cd project
git init
下面,应用您的邮件和登录名配备 Git:
git config --global user.email \" user1@yourdomain.com \"
git config --global user.name \"user1\"
下面,应用下列命令添加您的 Git HTTP 服务器:
git remote add origin http: //user1@git.yourdomain.com /user1.git
下面,建立一个名为 dev01 的目录并在其中添加一个文档:
mkdir dev01
echo \"This is my first application\" > dev01/file1
下面,将您创立的目录和文档添加到 Git 储存库:
git add .
下面,应用下列命令递交变更:
git commit -a -m \"Add files and directories\"
您将得到下列导出:
[master (root-commit) 0299d83] Add files and directories
1 file changed, 1 insertion( )
create mode 100644 dev01/file1
下面,应用下列命令将您的资料和目录上传入 HTTP Git 服务器:
git push origin master
系统软件会规定您给予登陆密码以浏览 Git 服务器:
Password for \'http://user1@git.yourdomain.com\':
联接后,您将得到下列导出:
Counting objects: 4, done.
Writing objects: 100% (4/4), 281 bytes | 281.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To http://git.yourdomain.com/user1.git
* [new branch] master -> master
您还能够采用下列命令立即从 Git 服务器免费下载您的储存库:
git clone http: //user1@git.yourdomain.com /user1.git
您将得到下列导出:
Cloning into \'user1\'...
Password for \'http://user1@git.yourdomain.com\':
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
结果
在上面的手册中,您学了怎样在 Debian 11 上应用 Nginx 设定 HTTP Git 服务器,您现在可以在当地开发工具中执行此设定,并应用命令行管理方法和追踪您的新项目。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。