Skip to content
Asher edited this page May 11, 2023 · 2 revisions

1. Install NGINX

Debian-based:

sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx

CentOS:

sudo yum install nginx

2. Edit configuration

Update /etc/nginx/sites-available/code-marketplace using sudo with the following configuration:

server {
    listen 80;
    listen [::]:80;
    server_name marketplace.example;

    location / {
        proxy_pass http://localhost:3001/;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

3. Enable code-marketplace

sudo ln -s ../sites-available/code-server /etc/nginx/sites-enabled/code-marketplace

4. TLS with Let's Encrypt

sudo certbot --non-interactive --redirect --agree-tos --nginx -d mydomain.com -m me@example.com
sudo systemctl restart nginx

5. TLS with self-signed certificate

You can use a tool like mkcert or generate one with openssl. For example:

mkdir /etc/nginx/certificates
cd /etc/nginx/certificates
openssl req -new -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes -out nginx-certificate.crt -keyout nginx.key

Update /etc/nginx/sites-available/code-marketplace using sudo with the following configuration:

server {
    listen 80;
    server_name marketplace.example;

    return 301 https://$server_name$request_uri/;
}

server {
    listen 443 ssl;
    server_name marketplace.example;

    ssl_certificate /etc/nginx/certificates/nginx-certificate.crt;
    ssl_certificate_key /etc/nginx/certificates/nginx.key;

    location / {
        proxy_pass http://localhost:3001/;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Then restart NGINX:

sudo systemctl restart nginx

6. DNS

Point marketplace.example to your server's IP address.