-
Notifications
You must be signed in to change notification settings - Fork 25
NGINX
Asher edited this page May 11, 2023
·
2 revisions
Debian-based:
sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx
CentOS:
sudo yum install nginx
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;
}
}
sudo ln -s ../sites-available/code-server /etc/nginx/sites-enabled/code-marketplace
sudo certbot --non-interactive --redirect --agree-tos --nginx -d mydomain.com -m [email protected]
sudo systemctl restart nginx
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
Point marketplace.example
to your server's IP address.