# Nginx Setup

### Step 1: Prerequisites

* Ubuntu/Debian server with root access
* Domain pointing to server
* DrakoPaste running on port **3000 (Optional)**

***

### Step 2: Install Nginx

```bash
sudo apt update
sudo apt install nginx
sudo systemctl enable --now nginx
```

***

### Step 3: SSL Certificate (Let’s Encrypt)

```bash
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com
```

{% hint style="success" %}
**Hint:** Replace `your-domain.com` with your actual domain.
{% endhint %}

***

### Step 4: Nginx Config

Create config:

```bash
sudo nano /etc/nginx/sites-available/drakopaste
```

Basic setup:

```nginx
server {
    listen 80;
    server_name paste.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name paste.example.com;

    ssl_certificate /etc/letsencrypt/live/paste.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/paste.example.com/privkey.pem;

    # Security headers
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
    add_header X-XSS-Protection "1; mode=block";
    add_header Referrer-Policy "strict-origin-when-cross-origin";

    # API routes
    location /api {
        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;
    }

    # Static assets with caching
    location /_next/static {
        proxy_pass http://localhost:3000;
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    # Next.js assets
    location /_next {
        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;
    }

    # Main application
    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;
    }
}
```

{% hint style="danger" %} <mark style="color:red;">**Important:**</mark> Make sure to change `paste.example.com` and `3000` if you are using a different port            &#x20;
{% endhint %}

Enable:

```bash
sudo ln -s /etc/nginx/sites-available/drakopaste /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
```

***

### Step 5: Firewall

```bash
sudo ufw allow 'Nginx Full'
sudo ufw status
```

***

### Step 6: Run DrakoPaste

```bash
cd /path/to/drakopaste
npm install
npm start
```

***

### Step 7: Test

* Visit [**https://your-domain.com**](https://your-domain.com/?utm_source=chatgpt.com)
* Create a paste

***
