Skip to content

Instantly share code, notes, and snippets.

@alisafariir
Created October 14, 2024 12:46
Show Gist options
  • Save alisafariir/d2f483a27fb2d92c085df68f5fc075b6 to your computer and use it in GitHub Desktop.
Save alisafariir/d2f483a27fb2d92c085df68f5fc075b6 to your computer and use it in GitHub Desktop.
create reverse proxy nginx server block (with certbot certificate)
#!/bin/bash
read -p "Please enter domain: " domain
read -p "Please enter proxy port: " port
echo "Creating server block for $domain"
sudo mkdir -p /var/www/$domain
sudo chown -R $USER:$USER /var/www/$domain
sudo chmod -R 755 /var/www
cat > /etc/nginx/sites-available/$domain << EOF
server {
listen 80;
listen [::]:80;
server_name $domain;
location / {
proxy_pass http://127.0.0.1:$port;
include proxy_params;
}
}
EOF
sudo ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/
sudo certbot --nginx -d $domain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment