This is step by by step guide for installing and configuring Nginx, creating self-signed OpenSSL certitificates, and exposing the service through HTTPS.
Step 1: Install Nginx
sudo apt update
sudo apt install nginx
Step 2: Generate a Self-Signed SSL Certificate with OpenSSL
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt
Follow the prompts to fill in the certificate information. For the Common Name (CN) field, use your server name: ec2-3-125-46-216.eu-central-1.compute.amazonaws.com.
Step 3: Configure Nginx
Create a new configuration file for your service:
sudo nano /etc/nginx/sites-available/ides
Add the following configuration:
server {
listen 80;
server_name ec2-3-125-46-216.eu-central-1.compute.amazonaws.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name ec2-3-125-46-216.eu-central-1.compute.amazonaws.com;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
location / {
proxy_pass http://127.0.0.1:8443;
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;
}
}
Step 4: Enable the Configuration
Create a symbolic link to enable the site:
sudo ln -s /etc/nginx/sites-available/ides /etc/nginx/sites-enabled/
Step 5: Test Nginx Configuration and Restart Nginx
sudo nginx -t
sudo systemctl restart nginx
Step 6: Firewall Configuration
If UFW (Uncomplicated Firewall) is enabled, allow HTTP and HTTPS traffic:
sudo ufw allow 'Nginx Full'
Step 7: Test Your Service
You should now be able to access your service securely via HTTPS using your server name (ec2-3-125-46-216.eu-central-1.compute.amazonaws.com).
Please note that since you're using a self-signed certificate, your browser may show a warning about the certificate not being trusted. This is expected with self-signed certificates and can be ignored for testing purposes. For production use, consider obtaining a trusted certificate from a certificate authority.
Comments
0 comments
Please sign in to leave a comment.