โ† Back to list

๐Ÿš€ Deploying Gitea on AWS EC2 with Docker, Nginx & SSL (Step-by-Step Guide)

In this guide, weโ€™ll walk through setting up your own self-hosted Git service using Gitea on an AWS EC2 instance. Weโ€™ll cover everythingโ€ฆ

Muhammad Anwar ยท 2026-03-26 06:58 ยท 0 claps ยท 1.9 min read
#gitea #docker #opesource #self-hosted #ubuntu
Open on Medium โ†—
Wiki topics: โ˜๏ธ ยท DevOps & Cloud ๐Ÿ”“ ยท Open Source

๐Ÿš€ Deploying Gitea on AWS EC2 with Docker, Nginx & SSL (Step-by-Step Guide)

In this guide, weโ€™ll walk through setting up your own self-hosted Git service using Gitea on an AWS EC2 instance. Weโ€™ll cover everything from server setup to Docker installation, reverse proxy configuration with Nginx, SSL setup, and final Gitea configuration.

โ˜๏ธ 1. Launch EC2 & Configure Security Group

Start by launching an Ubuntu EC2 instance (20.04 or 22.04 recommended).

๐Ÿ”“ Security Group Rules

Allow the following inbound ports:

PortPurpose22SSH access80HTTP (Nginx)443HTTPS (SSL)3000(optional) direct Gitea access222Gitea SSH (for Git operations)

๐Ÿ› ๏ธ 2. Install Dependencies

SSH into your EC2 instance:

ssh ubuntu@YOUR_EC2_IP

Update system

sudo apt update && sudo apt upgrade -y

๐Ÿณ Install Docker

sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker

Add user to docker group

sudo usermod -aG docker ubuntu
newgrp docker

๐Ÿ“ฆ Install Docker Compose

sudo apt install -y docker-compose

๐ŸŒ Install Nginx

sudo apt install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx

๐Ÿ” Install Certbot (SSL)

sudo apt install -y certbot python3-certbot-nginx

๐Ÿ“ 3. Setup Gitea with Docker

Create project directory:

mkdir gitea && cd gitea
cd gitea
nano docker-compose.yml

Create docker-compose.yml:

version: "3"
services:
  server:
    image: docker.gitea.com/gitea:1
    container_name: gitea
    restart: always
    environment:
      - USER_UID=1000
      - USER_GID=1000
    volumes:
      - ./gitea:/data
    ports:
      - "3000:3000"
      - "222:22"

Start Gitea

cd gitea
docker-compose up -d

Verify:

docker ps -a

๐ŸŒ 4. Configure Nginx (Reverse Proxy)

Create config:

sudo nano /etc/nginx/sites-available/gitea

Paste:

server {
    listen 80;
    server_name gitea.yourdomain.com;
    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable config:

sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

๐Ÿ” 5. Enable HTTPS (SSL)

Run:

sudo certbot --nginx

Follow prompts and select your domain.

After success, your site will be available at:

https://gitea.yourdomain.com

โš™๏ธ 6. Gitea Initial Setup (Web UI)

Open your browser:

https://gitea.yourdomain.com

Fill the form like this:

๐Ÿ—„๏ธ Database

  • Type: SQLite3
  • Path: /data/gitea/gitea.db

โš™๏ธ General Settings

Change SSH port to 222 and leave Rest of setting default

๐Ÿ‘ค Admin Account

Create your admin user:

  • Username
  • Email
  • Password

๐Ÿ”‘ 7. SSH Configuration (Important)

Since Docker maps:

222 โ†’ 22

๐Ÿ‘‰ You must use port 222 for Git operations.

Example clone:

git clone ssh://git@gitea.yourdomain.com:222/username/repo.git

๐Ÿš€ Final Result

You now have:

  • โœ… Self-hosted Git server (Gitea)
  • โœ… Running on Docker
  • โœ… Nginx reverse proxy
  • โœ… HTTPS enabled (SSL)
  • โœ… SSH Git access on port 222

๐Ÿง  Key Takeaways

  • Always use reverse proxy (Nginx) in production
  • Use HTTPS (SSL) for security
  • Configure correct Base URL in Gitea
  • Use custom SSH port (222) when using Docker

๐ŸŽฏ Whatโ€™s Next?

You can now:

  • Create repositories
  • Add team members
  • Setup CI/CD (Gitea Actions)
  • Configure backups
  • Integrate with your projects

๐Ÿ’ฌ Conclusion

With minimal resources, youโ€™ve built a powerful, self-hosted Git platform. Gitea is lightweight, fast, and perfect for teams or personal projects.


๋ฉ”ํƒ€๋ฐ์ดํ„ฐ
post_id
b0f44baa943d
slug
deploying-gitea-on-aws-ec2-with-docker-nginx-ssl-step-by-step-guide-b0f44baa943d
url
https://medium.com/@i211232/deploying-gitea-on-aws-ec2-with-docker-nginx-ssl-step-by-step-guide-b0f44baa943d
canonical_url
https://medium.com/@i211232/deploying-gitea-on-aws-ec2-with-docker-nginx-ssl-step-by-step-guide-b0f44baa943d
author_url
https://medium.com/@i211232
status
ok
fetched_at
2026-06-20 20:29:01