Ինչպես տեղադրել HTTP Git սերվերը Nginx-ով և SSL-ով Ubuntu 22.04-ում
Այս ձեռնարկը գոյություն ունի ՕՀ-ի այս տարբերակների համար
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Կիզակետային Fossa)
- Ubuntu 18.04 (Bionic Beaver)
- Ubuntu 16.04 (Xenial Xerus)
Այս էջում
- Նախադրյալներ
- Տեղադրեք Nginx վեբ սերվերը
- Ստեղծեք Git պահեստ
- Կարգավորեք Nginx-ը, որպեսզի սպասարկի Git պահեստը
- Ապահովեք Git HTTP սերվերը Let's Encrypt-ի միջոցով
- Հաճախորդից միացեք Git Repository-ին
- Եզրակացություն
Git-ը բաց կոդով տարբերակի կառավարման համակարգ է, որը հետևում է ձեր ծրագրաշարի փոփոխություններին աղբյուրի մակարդակով: Այն օգտագործվում է աշխարհի հազարավոր ծրագրավորողների կողմից՝ հետևելու և կառավարելու իրենց կոդի փոփոխությունները, վերադարձնելու այն նախկին փուլերին և ստեղծելու ֆայլերի և գրացուցակների այլընտրանքային տարբերակ:
HTTP Git Server-ը բաց կոդով նախագիծ է, որը թույլ է տալիս օգտատերերին կիսել Git պահեստները ձեր Տեղական ցանցի (LAN) միջոցով: Այն շատ պարզ է, հեշտ է կարգավորվում, և օգնում է մշակողներին կառավարել այն հրամանի տողի միջերեսից:
Այս ձեռնարկը կբացատրի Ubuntu 22.04-ում Nginx-ով HTTP Git պահոցի սերվերի տեղադրումը:
Նախադրյալներ
- Ubuntu 22.04-ով աշխատող սերվեր:
- Վավեր տիրույթի անունը նշված է ձեր սերվերի IP-ին:
- Ձեր սերվերի վրա կազմաձևված է արմատային գաղտնաբառը:
Տեղադրեք Nginx վեբ սերվերը
Այս գրառման մեջ մենք կօգտագործենք Nginx սերվերը Git պահեստը սպասարկելու համար, այնպես որ դուք պետք է տեղադրեք Nginx վեբ սերվերը և այլ անհրաժեշտ փաթեթներ ձեր սերվերում: Դուք կարող եք տեղադրել դրանք բոլորը՝ օգտագործելով հետևյալ հրամանը.
apt-get install nginx git fcgiwrap apache2-utils unzip -y
Բոլոր փաթեթները տեղադրելուց հետո կարող եք անցնել Git պահեստի ստեղծմանը:
Ստեղծեք Git պահեստ
Նախ, գրացուցակ՝ Git պահոցը Nginx վեբ արմատի ներսում պահելու համար.
mkdir /var/www/html/gitrepo
Հաջորդը, նավարկեք դեպի gitrepo և օգտագործողի համար ստեղծեք մեկ այլ գրացուցակ.
cd /var/www/html/gitrepo
mkdir hitesh.git
Հաջորդը, նավարկեք դեպի օգտվողի գրացուցակ և սկզբնավորեք Git պահոցը՝ օգտագործելով հետևյալ հրամանը.
cd hitesh.git
git --bare init
Դուք կստանաք հետևյալ արդյունքը.
Initialized empty Git repository in /var/www/html/gitrepo/hitesh.git/
Հաջորդը, թարմացրեք Git սերվերի տեղեկատվությունը հետևյալ հրամանով.
git update-server-info
Հաջորդը, փոխեք gitrepo-ի սեփականությունը և սահմանեք համապատասխան թույլտվությունը հետևյալ հրամանով.
chown -R www-data:www-data /var/www/html/gitrepo
chmod -R 755 /var/www/html/gitrepo
Հաջորդը, ստեղծեք օգտատեր, որը կոչվում է hitesh և սահմանեք գաղտնաբառ.
htpasswd -c /var/www/html/gitrepo/htpasswd hitesh
Դուք կարող եք սահմանել գաղտնաբառը, ինչպես ցույց է տրված ստորև.
New password:
Re-type new password:
Adding password for user hitesh
Դուք կարող եք ստուգել ձեր գաղտնաբառը՝ օգտագործելով հետևյալ հրամանը.
cat /var/www/html/gitrepo/htpasswd
Նմուշի ելք.
hitesh:$vcr2$AdyCEkaA$Fsq5nDbLhBDdafCQGBUsr2
Կարգավորեք Nginx-ը, որպեսզի սպասարկի Git պահեստը
Հաջորդը, ստեղծեք Nginx վիրտուալ հոսթի կազմաձևման ֆայլ՝ Git պահեստը ինտերնետում սպասարկելու համար:
nano /etc/nginx/conf.d/gitrepo.conf
Ավելացնել հետևյալ կոնֆիգուրացիաները.
server {
listen 80;
root /var/www/html/gitrepo;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name git.example.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/gitrepo/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/gitrepo;
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 2022-11-05 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
Nove 5 08:00:04 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Nove 5 08:00:04 ubuntu2204 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Nove 5 08:00:04 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.
Ապահովեք Git HTTP սերվերը Let's Encrypt-ի միջոցով
Նախքան սկսելը, դուք պետք է ձեր համակարգում տեղադրեք Certbot հաճախորդը՝ Let's Encrypt SSL-ը տեղադրելու և կառավարելու համար: Դուք կարող եք տեղադրել այն՝ օգտագործելով հետևյալ հրամանը.
apt-get install certbot python3-certbot-nginx -y
Երբ Certbot հաճախորդը տեղադրվի, գործարկեք հետևյալ հրամանը՝ ձեր կայքի համար Let's Encrypt SSL-ը ներբեռնելու և տեղադրելու համար.
certbot --nginx -d git.example.com
Տրամադրեք ձեր էլ. հասցեն և ընդունեք ծառայության ժամկետը, ինչպես ցույց է տրված ստորև.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for git.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/git.conf
Ընտրեք՝ վերահղել HTTP տրաֆիկը դեպի HTTPS.
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Մուտքագրեք 2 և սեղմեք Enter՝ գործընթացը սկսելու համար: Տեղադրումն ավարտվելուց հետո դուք պետք է տեսնեք հետևյալ արդյունքը.
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/git.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://git.example.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=git.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/git.example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/git.example.com/privkey.pem
Your cert will expire on 2023-02-06. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
Այս պահին ձեր Git HTTP սերվերն ապահովված է Let's Encrypt SSL-ով:
Հաճախորդից միացեք Git Repository-ին
Այս պահին Git HTTP սերվերը ստեղծվել է Nginx-ով և Let's Encrypt SSL-ով: Այժմ ժամանակն է միացնել այն հաճախորդի մեքենայից և փորձարկել այն:
Նախ, տեղադրեք Git փաթեթը հաճախորդի մեքենայի վրա՝ օգտագործելով հետևյալ հրամանը.
apt-get install git -y
Հաջորդը, ստեղծեք գրացուցակ ձեր նախագծի համար հետևյալ հրամանով.
mkdir project
Հաջորդը, նավարկեք ձեր նախագծի գրացուցակը և սկզբնավորեք Git-ը՝ օգտագործելով ստորև նշված հրամանը.
cd project
git init
Հաջորդը, կարգավորեք Git-ը՝ օգտագործելով ձեր էլ.փոստը և օգտվողի անունը.
git config --global user.email "[email "
git config --global user.name "hitesh"
Հաջորդը, ավելացրեք ձեր Git HTTP սերվերը՝ օգտագործելով հետևյալ հրամանը.
git remote add origin https://[email /hitesh.git
Հաջորդը, ստեղծեք տեղեկատու, որը կոչվում է տվյալներ և դրա մեջ ավելացրեք ֆայլ.
mkdir data
echo "This is my first application" > data/app
Հաջորդը, ավելացրեք ձեր ստեղծված գրացուցակը և ֆայլը 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 data/app
Հաջորդը, վերբեռնեք ձեր ֆայլը և գրացուցակը HTTP Git սերվերում՝ օգտագործելով հետևյալ հրամանը.
git push origin master
Ձեզանից կպահանջվի տրամադրել ձեր գաղտնաբառը՝ Git սերվեր մուտք գործելու համար.
Password for 'https://[email ':
Միանալուց հետո դուք կստանաք հետևյալ ելքը.
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 https://git.example.com/hitesh.git
* [new branch] master -> master
Դուք կարող եք նաև ներբեռնել ձեր պահոցը Git սերվերից ուղղակիորեն՝ օգտագործելով հետևյալ հրամանը.
git clone https://[email /hitesh.git
Դուք կստանաք հետևյալ արդյունքը.
Cloning into 'hitesh'...
Password for 'https://[email ':
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.
Եզրակացություն
Շնորհավորում եմ: դուք հաջողությամբ կարգավորել եք HTTP Git սերվերը Nginx-ով Ubuntu 22.04-ում: Օգտագործելով հրամանի տողը, այժմ կարող եք օգտագործել Git HTTP սերվերը ձեր տեղական զարգացման միջավայրում՝ ձեր նախագիծը կառավարելու և հետևելու համար: