For local development, it's useful to serve your app over HTTPS with a custom domain like yourproject.test. Here's how to set that up on Linux using Nginx and a self-signed certificate.

Step 1: Point Domain to Localhost

Edit /etc/hosts to map yourproject.test to 127.0.0.1:

echo "127.0.0.1 yourproject.test" | sudo tee -a /etc/hosts

Step 2: Generate a Self-Signed Certificate

Create an SSL directory and generate the certificate:

sudo mkdir -p /etc/nginx/ssl

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout /etc/nginx/ssl/yourproject.key \
  -out /etc/nginx/ssl/yourproject.crt \
  -subj "/C=US/ST=Local/L=Local/O=Dev/CN=yourproject.test"

Step 3: Configure Nginx

Create a new site configuration at /etc/nginx/sites-available/yourproject:

server {
    listen 443 ssl;
    server_name yourproject.test;

    ssl_certificate     /etc/nginx/ssl/yourproject.crt;
    ssl_certificate_key /etc/nginx/ssl/yourproject.key;

    root /var/www/yourproject;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 80;
    server_name yourproject.test;
    return 301 https://$host$request_uri;
}

Then enable the site and reload Nginx:

sudo mkdir -p /var/www/yourproject
echo "<h1>Hello yourproject!</h1>" | sudo tee /var/www/yourproject/index.html

sudo ln -s /etc/nginx/sites-available/yourproject /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 4: Visit in Browser

Navigate to:

https://yourproject.test

Click through the browser’s self-signed certificate warning.

Optional: Trust the Certificate Locally

To remove browser warnings (Linux systems with a CA trust store):

sudo cp /etc/nginx/ssl/yourproject.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates

Restart your browser if needed.

You now have HTTPS with a custom local domain β€” ideal for simulating a production environment during development.