這裏是Git的一個完整的配置,以HTTP,使用TLS加密,基本身份驗證和GitWeb(一個非常簡單的存儲庫查看器)。我假設這個版本庫的根目錄在/ home/git中。
# Remove this block if you don't want TLS
server {
listen 80;
server_name git.YOURDOMAIN.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl; # Replace 443 ssl by 80 if you don't want TLS
server_name git.YOURDOMAIN.com;
root /usr/share/gitweb; # Remove if you don't want Gitweb
error_log /home/git/nginx-error.log;
access_log /home/git/nginx-access.log;
# Remove ssl_* lines if you don't want TLS
ssl_certificate /etc/letsencrypt/live/git.YOURDOMAIN.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/git.YOURDOMAIN.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
# Remove auth_* if you don't want HTTP Basic Auth
auth_basic "YOURDOMAIN Git";
auth_basic_user_file /etc/nginx/.htpasswd;
# static repo files for cloning over https
location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
root /home/git/;
}
# requests that need to go to git-http-backend
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
root /home/git/;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param PATH_INFO $uri;
fastcgi_param GIT_PROJECT_ROOT $document_root;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param REMOTE_USER $remote_user;
include fastcgi_params;
}
# Remove all conf beyond if you don't want Gitweb
try_files $uri @gitweb;
location @gitweb {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/gitweb.cgi;
fastcgi_param PATH_INFO $uri;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
include fastcgi_params;
}
}
您必須安裝的Git,和的GitWeb FastCgiWrap:
sudo apt-get install git gitweb fcgiwrap
對於TLS,我用Let's Encrypt免費證書。
sudo letsencrypt certonly -d git.YOURDOMAIN.com --rsa-key-size 4096
要訪問Gitweb,只需瀏覽到git.YOURDOMAIN.com。你還需要將它配置設置倉庫根:
sudo vim /etc/gitweb.conf
爲了得到HTTP基本認證,您必須使用htpasswd
命令將用戶添加到/etc/nginx/.htpasswd
:
sudo apt-get install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd username
刪除-c
在下次運行命令時切換,因爲它只創建文件(Nginx默認情況下在其配置目錄中沒有.htpasswd文件)。
如果你想要更復雜,功能強大的GitHub,請檢查Gitlab。
我按照這個例子在nginx上設置git。然而,每次我嘗試克隆回購時,我最終都會報錯: '致命:http://:9000/git/test。混帳/信息/裁判無效:這是一個git重新 pository' 有沒有錯誤的/var/log/nginx/error.log和訪問日誌,我可以看到: - - [03/Oct/2015:08:35:42 +0200]「GET /git/test.git/info/refs?service=git-upload-pack HTTP/1.1」200 424859「 - 」「git/1.9.4.msysgit .1「 您是否遇到類似問題? 謝謝, Janusz –
不行,但要確保它是一個由'git init --bare'創建的裸倉庫。也就是說,不要託管代碼,除非你在做'git clone --bare' - 除此之外,谷歌應該幫助 –
我最終找到了適合我的例子:http://serverfault.com/questions/483726 /如何對化妝的git-智能HTTP的運輸工作,上nginx的。謝謝。 –