Nginx Setup
For VPS, cloud servers, and dedicated servers with SSH and sudo access.
1. Set Variables
Replace these values:
bash
export ACME_SERVER="your Server URL"
export EAB_KID="your EAB MAC ID"
export EAB_HMAC_KEY="your EAB MAC key"
export EMAIL="admin@example.com"
export DOMAIN="example.com"
export WEBROOT="/var/www/example.com/public"2. Install acme.sh
bash
curl https://get.acme.sh | sh -s email="$EMAIL"
source ~/.bashrc 2>/dev/null || source ~/.zshrc 2>/dev/null || true3. Register the ACME Account
bash
~/.acme.sh/acme.sh --register-account \
--server "$ACME_SERVER" \
--eab-kid "$EAB_KID" \
--eab-hmac-key "$EAB_HMAC_KEY" \
-m "$EMAIL"4. Issue the Certificate
bash
~/.acme.sh/acme.sh --issue \
--server "$ACME_SERVER" \
-d "$DOMAIN" \
-w "$WEBROOT"Include www:
bash
~/.acme.sh/acme.sh --issue \
--server "$ACME_SERVER" \
-d "$DOMAIN" \
-d "www.$DOMAIN" \
-w "$WEBROOT"5. Install the Certificate
bash
sudo mkdir -p "/etc/ssl/12ssl/$DOMAIN"
sudo ~/.acme.sh/acme.sh --install-cert -d "$DOMAIN" \
--key-file "/etc/ssl/12ssl/$DOMAIN/privkey.pem" \
--fullchain-file "/etc/ssl/12ssl/$DOMAIN/fullchain.pem" \
--reloadcmd "systemctl reload nginx"6. Configure Nginx
bash
sudo nano /etc/nginx/sites-available/example.comExample:
nginx
server {
listen 443 ssl http2;
server_name example.com www.example.com;
root /var/www/example.com/public;
index index.html index.php;
ssl_certificate /etc/ssl/12ssl/example.com/fullchain.pem;
ssl_certificate_key /etc/ssl/12ssl/example.com/privkey.pem;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}Check and reload:
bash
sudo nginx -t
sudo systemctl reload nginx7. Check
bash
curl -I "https://$DOMAIN"Open:
text
https://example.com