sandbox.gitwit.dev setup

jamesmurdza

James Murdza

Posted on October 4, 2024

sandbox.gitwit.dev setup

Set up the server:

sudo yum install nginx # Install Nginx

sudo yum install certbot python3-certbot-nginx # Install Certbot for SSL management

sudo certbot certonly --nginx # Obtain an SSL certificate for the domain

(Certificate is saved at /etc/letsencrypt/live/sandbox.gitwit.dev/fullchain.pem)

Edit the Nginx configuration file:
vim /etc/nginx/nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

    server {
        listen 443 ssl;
        server_name api.sandbox.gitwit.dev;

        ssl_certificate /etc/letsencrypt/live/sandbox.gitwit.dev/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/sandbox.gitwit.dev/privkey.pem;

        location / {
            proxy_pass http://localhost:4000;
            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;
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Install PM2 for process management:
sudo npm install -g pm2

Clone your project repository:
cd ~
git clone https://github.com/jamesmurdza/sandbox/
cd sandbox

Start your server using PM2:
npx pm2 start dist/index.js --name sandbox-server --log-date-format 'YYYY-MM-DD HH:mm Z' --output ./logs/output.log --error ./logs/error.log

See logs:

Use this to view the logs:
npx pm2 logs sandbox-server

Redeploy proxy server:

This is only necessary if nginx.conf changes.

Test Nginx configuration for any errors:
sudo nginx -t

Reload Nginx with the updated configuration:
sudo systemctl reload nginx

Redeploy Sandbox server:

This is necessary after changes to /backend/server/ in the git repository:

cd ~/sandbox/backend/server/ # Go to the backend server directory
git pull # Pull the latest code from the repository
npm install # Install any new dependencies
npm run build # Rebuild the project
npx pm2 restart sandbox-server # Restart the server using PM2

Renew SSL certificate:

To renew your SSL certificate:
sudo certbot renew --nginx
sudo certbot

💖 💪 🙅 🚩
jamesmurdza
James Murdza

Posted on October 4, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related