# Nginx Configuration

{% stepper %}
{% step %}

### Prerequisites

```bash
sudo mkdir -p /var/www
cd /var/www
git clone https://github.com/YouSeeMeRunning2/DrakoBot.git # You won't be able to use my repository
sudo mv /var/www/DrakoBot /var/www/drakobot # Ensure the folder is named drakobot
```

{% hint style="info" %}
Run `ls` to verify the folder name before renaming.
{% endhint %}

{% hint style="warning" %}
You won't be able to use my git repository, it's just an example. Your folder may not be called DrakoBot to start with — update the `sudo mv` command to fit your needs.
{% endhint %}
{% endstep %}

{% step %}

### Create A Records

Create the following DNS A records:

* **Host:** `dashboard`
* **Value:** `<Server IP>`
  {% endstep %}

{% step %}

### Install NVM and Node.js 18.20.7

```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
\. "$HOME/.nvm/nvm.sh"
nvm install 18
node -v
```

{% hint style="info" %}
Verify the installation by running `node -v`. It should output `v18.x.x`.
{% endhint %}
{% endstep %}

{% step %}

### Install Nginx

```bash
sudo apt update
sudo apt install -y nginx
```

{% endstep %}

{% step %}

### Install Dashboard Dependencies

```bash
cd /var/www/drakobot/dashboard
npm install
```

{% endstep %}

{% step %}

### Create Nginx Configuration

Edit the Nginx configuration file:

```bash
sudo nano /etc/nginx/sites-available/dashboard.youseemerunning.com
```

{% hint style="warning" %}
Replace `youseemerunning.com` with your own domain.
{% endhint %}

Add the following configuration:

```nginx
server {
    server_name dashboard.youseemerunning.com;

    large_client_header_buffers 4 32k;
    client_header_buffer_size 32k;

    location / {
        proxy_pass http://localhost:7000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

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

    # Example SSL configuration (uncomment after running: sudo certbot --nginx -d dashboard.youseemerunning.com)
    # listen 443 ssl;
    # ssl_certificate /etc/letsencrypt/live/dashboard.youseemerunning.com/fullchain.pem;
    # ssl_certificate_key /etc/letsencrypt/live/dashboard.youseemerunning.com/privkey.pem;
    # include /etc/letsencrypt/options-ssl-nginx.conf;
    # ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    listen 80;
}

# Example HTTPS redirect (uncomment after enabling SSL above)
# server {
#     listen 80;
#     server_name dashboard.youseemerunning.com;
#     return 301 https://$host$request_uri;
# }
```

{% hint style="info" %}
Press `CTRL + X`, then `Y`, then `Enter` to save the file.
{% endhint %}

{% hint style="warning" %}
Replace `youseemerunning.com` with your own domain and update **5173** to match your port
{% endhint %}
{% endstep %}

{% step %}

### Enable the Site and Restart Nginx

```bash
sudo ln -s /etc/nginx/sites-available/dashboard.youseemerunning.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
```

{% hint style="info" %}
Run `sudo nginx -t` to test the configuration before restarting.
{% endhint %}

{% hint style="warning" %}
Replace `youseemerunning.com` with your own domain.
{% endhint %}
{% endstep %}

{% step %}

### Install SSL Certificate

```bash
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d dashboard.youseemerunning.com
```

{% hint style="info" %}
Follow the prompts to complete the SSL setup.
{% endhint %}

{% hint style="warning" %}
Replace `youseemerunning.com` with your own domain.
{% endhint %}
{% endstep %}

{% step %}

### Edit the Bot Configuration

```bash
cd /var/www/drakobot
sudo nano config/modules/dashboard.yml
```

Update the bot settings with the following values:

```yaml
Url: https://dashboard.youseemerunning.com
```

{% hint style="warning" %}
Replace `youseemerunning.com` with your own domain.
{% endhint %}
{% endstep %}

{% step %}

### Install PM2 and Run Services

```bash
npm install -g pm2

cd /var/www/drakobot
npm install
pm2 start npm --name "drakobot" -- run start

cd /var/www/drakobot/dashboard
pm2 start npm --name "dashboard" -- run dev

pm2 save
pm2 startup
```

{% hint style="info" %}
PM2 keeps both the bot and dashboard running. The dashboard runs Vite on port 5173.
{% endhint %}
{% endstep %}
{% endstepper %}

Your Drako Bot dashboard should now be up and running!
