{"id":4169,"date":"2020-10-25T02:24:37","date_gmt":"2020-10-24T18:24:37","guid":{"rendered":"https:\/\/www.ookangzheng.com\/?p=4169"},"modified":"2021-09-27T12:01:14","modified_gmt":"2021-09-27T04:01:14","slug":"self-host-git-with-gitea-on-debian","status":"publish","type":"post","link":"https:\/\/www.ookangzheng.com\/self-host-git-with-gitea-on-debian\/","title":{"rendered":"Self-host Git with Gitea on Debian"},"content":{"rendered":"\n
Last update: Sep 18, 2021<\/p>\n\n\n\n
We use SQLite as database in this example tutorial.<\/p>\n\n\n\n
apt update \napt install sqlite3 git -y<\/code><\/pre>\n\n\n\nCreate a user for Gitea<\/h2>\n\n\n\nadduser --system --shell \/bin\/bash --group --disabled-password --home \/root\/gitea-repositories gitea<\/code><\/pre>\n\n\n\nDownload Gitea binary file<\/h3>\n\n\n\n## Download Gitea \n\nexport VERSION=1.15.3 && wget -O \/tmp\/gitea https:\/\/dl.gitea.io\/gitea\/${VERSION}\/gitea-${VERSION}-linux-amd64 && mv \/tmp\/gitea \/usr\/local\/bin && chmod +x \/usr\/local\/bin\/gitea<\/code><\/pre>\n\n\n\n## Create gitea directory\n\nmkdir -p \/var\/lib\/gitea\/{custom,data,log}\nchown gitea:gitea \/var\/lib\/gitea\/{custom,data,log}\nchmod 750 \/var\/lib\/gitea\/{data,log}<\/code><\/pre>\n\n\n\nGitea Systemd startup<\/h3>\n\n\n\nnano \/etc\/systemd\/system\/gitea.service\n\n## Paste following lines \n\n[Unit]\nDescription=Gitea (Git with a cup of tea)\nAfter=syslog.target\nAfter=network.target\n\n[Service]\n# Modify these two values and uncomment them if you have\n# repos with lots of files and get an HTTP error 500 because\n# of that\n\n#LimitMEMLOCK=infinity\n#LimitNOFILE=65535\nRestartSec=2s\nType=simple\nUser=root\nGroup=root\nWorkingDirectory=\/var\/lib\/gitea\/\n\nExecStart=\/usr\/local\/bin\/gitea -p 3001 --config \/var\/lib\/gitea\/custom\/conf\/app.ini\nRestart=always\nEnvironment=USER=root HOME=\/root\/gitea-repositories GITEA_WORK_DIR=\/var\/lib\/gitea\n\n# If you want to bind Gitea to a port below 1024, uncomment\n# the two values below, or use socket activation to pass Gitea its ports as above\n\n#CapabilityBoundingSet=CAP_NET_BIND_SERVICE\n#AmbientCapabilities=CAP_NET_BIND_SERVICE\n###\n\n[Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n\n\n\nsudo systemctl daemon-reload<\/code>\nsudo systemctl enable --now gitea<\/code>.service<\/pre>\n\n\n\nThe default startup port is 3000<\/code>, if you wanna change it, ensure modify gitea.service<\/code> with additional option -p 3001<\/code> <\/p>\n\n\n\nExample: <\/p>\n\n\n\n
ExecStart=\/usr\/local\/bin\/gitea -p 3001 --config \/var\/lib\/gitea\/conf\/app.ini<\/code><\/pre>\n\n\n\nNginx as reverse proxy with SSL<\/h3>\n\n\n\nserver {\n listen 80;\n listen [::]:80;\n listen 443 ssl http2;\n listen [::]:443 ssl http2;\n ssl_certificate \/root\/.acme.sh\/xxx.cer;\n ssl_certificate_key \/root\/.acme.sh\/xxx.key;\n ssl_protocols TLSv1.2 TLSv1.3;\n ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;\n ssl_prefer_server_ciphers on;\n ssl_session_timeout 10m;\n ssl_session_cache builtin:1000 shared:SSL:10m;\n ssl_buffer_size 1400;\n add_header Strict-Transport-Security max-age=15768000;\n ssl_stapling on;\n ssl_stapling_verify on;\n server_name xxx;\n access_log off;\n # index index.html index.htm index.php;\n\n if ($ssl_protocol = \"\") { return 301 https:\/\/$host$request_uri; }\n\n location \/ {\n proxy_pass http:\/\/127.0.0.1:3001;\n proxy_set_header Host $http_host;\n proxy_set_header X-Forwarded-Host $host;\n proxy_set_header X-Forwarded-Server $host;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n client_max_body_size 0;\n proxy_max_temp_file_size 0;\n proxy_redirect off;\n proxy_read_timeout 120;\n add_header Pragma \"no-cache\";\n add_header Cache-Control \"no-cache\";\n }\n\n}\n <\/pre>\n\n\n\nBackup and migration<\/h3>\n\n\n\n# Backup and migration with rclone.org\n\nnano \/root\/backup-git.sh\n\n## Paste following line\n\n## Gitea configuration store in \/var\/lib\/gitea\/custom, data, log\n## Gitea git repo store at \/root\/gitea-repositories\n\nrm \/root\/backup-git-*\n\nrm -rf \/root\/backup-git\n\nmkdir \/root\/backup-git\nzip -r data.zip \/var\/lib\/gitea\/ \/etc\/systemd\/system\/gitea.service\nzip -r \/root\/backup-git\/gitea.zip \/root\/gitea-repositories\nzip -r \"\/root\/backup-git-$(date '+%Y-%m-%d-%H-%M').zip\" \/root\/backup-git\n\necho \"Backup git\"\nrclone copy \/root\/backup-git-* xxxx:\/ -c -v\n\nrm \/root\/backup-git-*\n\nexit 0<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Last update: Sep 18, 2021 We use SQLite as database in this example tutorial. Create a user for Gitea Download…<\/p>\n","protected":false},"author":1,"featured_media":4206,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,32],"tags":[],"class_list":["post-4169","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-technology"],"_links":{"self":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/4169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/comments?post=4169"}],"version-history":[{"count":2,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/4169\/revisions"}],"predecessor-version":[{"id":4446,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/4169\/revisions\/4446"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/media\/4206"}],"wp:attachment":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/media?parent=4169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/categories?post=4169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/tags?post=4169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}