2020-03-11 18:21:41
现在使用ISPProtect扫描Web服务器的恶意软件。 免费试用
Git是一个免费的开源版本控制系统,可用于跟踪代码的更改。 Git允许您为同一应用程序创建许多存储库,并在多个人员之间协调这些文件的工作。 它主要用于软件开发中的源代码管理。
在本文中,我们将学习如何在Ubuntu 16.04上安装带有Nginx的HTTP Git服务器。
要求
新的Ubuntu 16.04服务器安装在您的系统上。 具有root权限的Sudo用户。 在您的服务器上配置静态IP地址192.168.15.189开始之前,您将需要使用最新的稳定版本来更新系统。
您可以通过运行以下命令来执行此操作:
sudo apt-get update -y
sudo apt-get upgrade -y
更新系统后,重新启动系统并使用sudo用户登录。
首先,您将需要安装一些所需的软件包,包括nginx,git,nano和fcgiwrap到您的系统。 您可以通过运行以下命令来安装它们:
sudo apt-get install nginx git nano fcgiwrap apache2-utils -y
一旦安装了所有必需的软件包,您将需要为Git存储库创建一个目录。 您可以通过运行以下命令来执行此操作:
sudo mkdir /var/www/html/git
接下来,给予Git目录的正确许可:
sudo chown -R www-data:www-data /var/www/html/git
完成后,您可以继续配置Nginx Web服务器。
首先,您需要配置Nginx将Git流量传递给Git。 您可以通过编辑Nginx默认配置文件来执行此操作:
sudo nano /etc/nginx/sites-available/default
更改文件如下所示:
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/git;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
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, just to make sure nginx doesn't suddenly cut the connection add this.
auth_basic "Git Login"; # Whatever text will do.
auth_basic_user_file "/var/www/html/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/html/git; # /var/www/git is 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
}
}
完成后保存并关闭文件。 然后使用以下命令测试Nginx的任何配置错误:
sudo nginx -t
如果一切正常,您应该看到以下输出:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
接下来,您将需要创建一个用户帐户,您需要使用它来浏览提交到存储库。 您可以使用htpasswd实用程序创建名称为hitesh的用户:
sudo htpasswd -c /var/www/html/git/htpasswd hitesh
最后,重新启动Nginx以使用以下命令应用所有更改:
sudo systemctl restart nginx
您可以使用以下命令检查Nginx服务器的状态:
sudo 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 Tue 2017-06-20 23:00:11 IST; 51min ago
Process: 12415 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 7616 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
Process: 12423 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 12419 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 12427 (nginx)
CGroup: /system.slice/nginx.service
??????12427 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
??????12431 nginx: worker process
Jun 20 23:00:11 localhost systemd[1]: Stopped A high performance web server and a reverse proxy server.
Jun 20 23:00:11 localhost systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 20 23:00:11 localhost systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
Jun 20 23:00:11 localhost systemd[1]: Started A high performance web server and a reverse proxy server.
一旦配置正确,就可以建立Git仓库了。
您可以使用以下命令创建名称为repo.git的存储库:
cd /var/www/html/git
sudo mkdir hitesh.gitt
sudo git –bare initt
sudo git update-server-info
sudo chown -R www-data.www-data .
sudo chmod -R 777 .
接下来,您将需要通过UFW防火墙允许http服务。 默认情况下,UFW在系统中被禁用,因此您需要先启用它。 您可以使用以下命令启用它:
sudo ufw enable
一旦UFW防火墙启用,您可以通过运行以下命令来允许HTTP服务:
sudo ufw allow http
您现在可以通过运行以下命令检查UFW防火墙的状态:
sudo ufw status
好的,这是服务器端配置。 您现在可以转到客户端来测试Git。
在启动之前,您将需要在客户端系统上安装git。 您可以使用以下命令安装它:
sudo apt-get install git -y
首先,使用以下命令创建本地存储库:
sudo mkdir ~/testproject
接下来,将目录更改为testproject并使用以下命令启动新的远程存储库:
cd ~/testproject
git init
git remote add origin http://hitesh@192.168.15.189/hitesh.git
接下来,使用以下命令创建一些文件和目录:
mkdir test1 test2 test3
echo “This is my first repository” > test1/repo1
echo “This is my second repository” > test2/repo2
echo “This is my third repository” > test3/repo3
接下来,运行以下命令将所有文件和目录添加到存储库中:
git add .
git commit -a -m “Add files and directoires”
您应该看到以下输出:
[master 002fac9] Add files and directoires
3 files changed, 3 insertions(+)
create mode 100644 repo1
create mode 100644 repo2
create mode 100644 repo3
接下来,使用以下命令将所有文件和目录推送到Git服务器:
git push origin master
您应该看到以下输出:
Password for 'http://hitesh@192.168.15.189':
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (5/5), 422 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To http://hitesh@192.168.15.189/hitesh.git
68f1270..002fac9 master -> master
现在,您的所有文件和目录已经提交到您的Git服务器。
您的Git存储库创建过程现已完成。 您将来可以轻松克隆您的存储库。 您可以使用远程系统上的以下命令克隆您的存储库:
git clone hitesh@192.168.15.189:/var/www/html/git/hitesh.git
您应该看到以下输出:
Cloning into 'hitesh'...
hitesh@192.168.15.189's password:
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (3/3), done.
Receiving objects: 100% (8/8), 598 bytes | 0 bytes/s, done.
remote: Total 8 (delta 0), reused 0 (delta 0)
Checking connectivity... done.
现在,使用以下命令将目录更改为克隆的存储库:
cd hitesh
tree
您应该看到以下输出:
.
|-- test1
| `-- repo1
|-- test2
| `-- repo2
`-- test3
`-- repo3
3 directories, 3 files
Nginx HTTP2配置教程
06-23
Ubuntu安装mongodb数据库服务器
05-29
CentOS7安装配置PostgreSQL数据库服务器
06-20
TR260 G2服务器内存DIMM安装配置和内存插的槽分布
06-23
TR280服务器是否支持USB光驱启动进行系统安装?
06-26
Nginx使用教程(一):下载并编译安装Nginx
07-07
Ubuntu 16.04安装Docker Compose及简单的使用示例
05-21
Ubuntu下迁移通过apt安装的MySQL数据库文件目录
07-18
CentOS7源码编译安装Nginx
06-11
如何在CentOS 7上安装Nginx
07-05
搭建自己的Git服务器
07-08
服务器在主机外接SCSI卡连接SureSCSI310R阵列柜后,原系统无法正常启动。
07-01
T270 G5服务器liunx系统运行过程报“nautilus崩溃”错误的原因?
07-18
Zabbix3.0监控Apache2.4服务器状态
07-17
Ubuntu 16.04 配置 Let’s Encrypt 实现站点 SSL
05-13
Ubuntu 16.04使用Docker部署WordPress
06-13
Ubuntu系统配置samba实现文件夹共享
06-22
Nginx ngx_HTTP_limit_conn ngx_HTTP_limit_conn模块(请求限制和连接数限制)使用指南
03-20
Nginx使用教程(四):提高Nginx网络吞吐量之buffers优化
04-05
Nginx配置basic_auth密码验证
06-13
服务器安全工具(服务器安全防护软件) 1.2.2.0 免费绿色版
329.2K
下载BIGEMAP离线地图服务器(离线地图开发者工具) v15.4.0.0 破解版
48.9M
下载C-Lodop云打印服务器(云打印工具)v4.115官方版
9.3M
下载tomcat7.0 (Web 应用服务器)官方版
9.3M
下载xp iis(Web服务器)6.0 中文版
13.4M
下载深蓝群Ping工具 V2.1 绿色版 多服务器多线程群ping工具
487 KB
下载网络文件服务器下载
837.6KB
下载HTTPSniffer绿色版 v1.2
255.1K
下载3d蓝光播放器(高清3D影音播放软件) V1.8.0.4 绿色免安装版
36.8 MB
下载Emby Server(流媒体服务软件,)v4.0.2.0 破解版
101M
下载HofoSetup(安装程序制作软件)v8.5.4 破解版
5.7M
下载Virtual CloneDrive V5.4.4.0 汉化纯净安装版
1.6MB
下载securecrt(SSH远程终端服务软件) v9.0 破解版
67.7MB
下载硬盘安装器(系统安装工具) 1.6.10.6 中文版
17.35 MB
下载雨燕投屏(投屏办公服务软件) 3.10.16.0 最新版
3.5M
下载黄山IE修复专家 v9.0 官方安装版
4.44MB
下载360安全桌面下载
42.53M
下载Cerberus FTP Server Enterprise下载
28.7M
下载DesktopDiGitalClock
214 KB
下载FileZilla Server中文版 v0.9.60.0
2.14 MB
下载