Created
January 18, 2026 18:08
-
-
Save abubaker417/c9454768cc78583c1f9424395dfc10b9 to your computer and use it in GitHub Desktop.
Server Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Ubuntu | |
| sudo apt update -y | |
| # Install Docker | |
| https://docs.docker.com/engine/install/ubuntu/ | |
| # Install Docker Compose | |
| sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
| sudo chmod +x /usr/local/bin/docker-compose | |
| # Add ubuntu into Docker Group | |
| sudo usermod -aG docker $USER | |
| # Clone the Repository | |
| git clone https:// | |
| # Only owner can read/write .env file | |
| chmod 600 .env | |
| # Verify | |
| ls -la .env | |
| # Should show: -rw------- 1 ubuntu ubuntu | |
| # SSH key for server | |
| ssh-keygen -t ed25519 -C "github-actions-deploy" | |
| cat ~/.ssh/id_ed25519.pub => copy and created new deploy key on github setting and also add thi into authorized_key | |
| cat ~/.ssh/id_ed25519 => copy and add into repository secret into SSH_PRIVATE_KEY variable | |
| # change own ship so that user -> ubuntu | |
| sudo chown -R ubuntu:ubuntu /var/www | |
| # Permission check | |
| ~/.ssh → 700 (drwx------) | |
| ~/.ssh/id_ed25519 → 600 (-rw-------) | |
| ~/.ssh/id_ed25519.pub → 644 (-rw-r--r--) | |
| ~/.ssh/authorized_keys → 600 (-rw-------) | |
| ~/.ssh/known_hosts → 600 (-rw-------) | |
| ls -ld ~/.ssh ~/.ssh/authorized_keys ~/.ssh/id_ed25519 | |
| ubuntu ubuntu | |
| # Nginx configration | |
| # Install Nginx web server and package for SSL | |
| sudo apt update -y | |
| sudo apt install nginx -y | |
| sudo apt install certbot python3-certbot-nginx -y | |
| sudo systemctl start nginx | |
| sudo systemctl enable nginx | |
| sudo systemctl status nginx | |
| # create file | |
| sudo nano /etc/nginx/sites-available/fastapi | |
| # Configration content | |
| server { | |
| listen 80; | |
| server_name example.info www.example.info; | |
| location / { | |
| proxy_pass http://127.0.0.1:8000; | |
| proxy_http_version 1.1; | |
| 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; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "upgrade"; | |
| } | |
| } | |
| # Syntax Check | |
| sudo nginx -t | |
| # Enable Site create syblink | |
| sudo ln -s /etc/nginx/sites-available/fastapi /etc/nginx/sites-enabled/ | |
| # Test and Reload Site | |
| sudo nginx -t | |
| sudo systemctl reload nginx => not start the whole domain from again | |
| sudo systemctl restart nginx => it will start all from first steps | |
| # Create SSL | |
| sudo certbot --nginx -d devopslab.info www.devopslab.info => create ssl for domain | |
| # if you update in configration file then these commands | |
| sudo nginx -t | |
| sudo systemctl reload nginx | |
| # For same ip after stopped the instance then should attached the elastic ip | |
| On Ngixn DSN Elastic IP will use | |
| # Environment Implemenation | |
| # Use .env.development | |
| docker-compose --env-file .env.development up | |
| # Use .env.production | |
| docker-compose --env-file .env.production up | |
| # Use default .env (no flag needed) | |
| docker-compose up | |
| ## Golden rules (memorize this) | |
| | What you changed | What to run | | |
| | -------------------------------- | ------------------------------------------------------------ | | |
| | **Only app code** (Python files) | `docker-compose restart` | | |
| | **requirements.txt** | `docker-compose build` + `up` | | |
| | **Dockerfile** | `docker-compose build` + `up` | | |
| | **docker-compose.yml** | `docker-compose up -d` | | |
| | **Dockerfile + compose** | `docker-compose build` + `up` | | |
| | **Everything / not sure** | `docker-compose down && docker-compose build --no-cache && docker-compose up -d` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment