使用 Docker 安装

1、先安装 docker 和 docker-compose
2、安装数据库,这里使用 postgresql
创建数据库和用户:

  1. CREATE USER gitea WITH PASSWORD 'gitea';
  2. CREATE DATABASE gitea owner=gitea;
  3. GRANT ALL privileges ON DATABASE gitea TO gitea;

3、安装 nginx,建议通过编译源码进行安装。
安装之后,配置nginx,可以通过 gitea.chensoul.com 访问 gitea:

  1. server {
  2. listen 80;
  3. listen [::]:80;
  4. server_name gitea.chensoul.com;
  5. location / {
  6. proxy_pass http://127.0.0.1:3000;
  7. }
  8. }

另外,需要添加dns解析:

  1. gitea.chensoul.com
  2. postgres.chensoul.com

如果,需要开启SSL,则可以通过 acme.sh 申请证书:

4、通过 docker-compose 安装 gitea
gitea.yaml

  1. version: "3"
  2. services:
  3. server:
  4. image: gitea/gitea:1
  5. container_name: gitea
  6. environment:
  7. - USER_UID=1000
  8. - USER_GID=1000
  9. - DB_TYPE=postgres
  10. - DB_HOST=postgres.chensoul.com:5432
  11. - DB_NAME=gitea
  12. - DB_USER=gitea
  13. - DB_PASSWD=gitea
  14. restart: always
  15. volumes:
  16. - /data/gitea:/data/gitea
  17. - /etc/timezone:/etc/timezone:ro
  18. - /etc/localtime:/etc/localtime:ro
  19. ports:
  20. - "3000:3000"
  21. - "2222:22"

启动容器:

  1. docker-compose -f gitea.yaml up -d

4、初始化 gitea,通过 https://gitea.chensoul.com 访问 gitea,并做相应设置
gitea-setup-1
gitea-setup-2
5、配置域名

  1. server {
  2. listen 80;
  3. listen [::]:80;
  4. server_name gitea.chensoul.com;
  5. return 301 https://$host$request_uri;
  6. }
  7. server {
  8. listen 443 ssl http2;
  9. listen [::]:443 ssl http2;
  10. server_name gitea.chensoul.com;
  11. # SSL
  12. ssl_certificate /usr/local/nginx/ssl/fullchain.cer;
  13. ssl_certificate_key /usr/local/nginx/ssl/chensoul.com.key;
  14. ssl_session_cache shared:SSL:1m;
  15. ssl_session_timeout 5m;
  16. ssl_ciphers HIGH:!aNULL:!MD5;
  17. ssl_prefer_server_ciphers on;
  18. # logging
  19. access_log /var/log/nginx/gitea.chensoul.com.access.log;
  20. error_log /var/log/nginx/gitea.chensoul.com.error.log warn;
  21. # reverse proxy
  22. location / {
  23. proxy_pass http://127.0.0.1:3000;
  24. # Proxy Config
  25. proxy_http_version 1.1;
  26. proxy_cache_bypass $http_upgrade;
  27. # Proxy headers
  28. proxy_set_header Upgrade $http_upgrade;
  29. proxy_set_header Connection $connection_upgrade;
  30. proxy_set_header Host $host;
  31. proxy_set_header X-Real-IP $remote_addr;
  32. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  33. proxy_set_header X-Forwarded-Proto $scheme;
  34. proxy_set_header X-Forwarded-Host $host;
  35. proxy_set_header X-Forwarded-Port $server_port;
  36. # Proxy timeouts
  37. proxy_connect_timeout 60s;
  38. proxy_send_timeout 60s;
  39. proxy_read_timeout 60s;
  40. }
  41. # additional config
  42. # favicon.ico
  43. location = /favicon.ico {
  44. log_not_found off;
  45. access_log off;
  46. }
  47. # gzip
  48. gzip on;
  49. gzip_vary on;
  50. gzip_proxied any;
  51. gzip_comp_level 6;
  52. gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
  53. }

映射SSH端口:
https://ssr.carrotwu.com/post/42
https://www.whao.fun/posts/2021/03/02/gitea-install.html
https://www.escapelife.site/posts/af961a30.html
5、卸载

  1. docker-compose -f git.yaml down
  2. rm -rf /data/gitea/*