Skip to content

Instantly share code, notes, and snippets.

@mjawaids
Last active October 21, 2025 14:27
Show Gist options
  • Select an option

  • Save mjawaids/072ea7f47f213145b66e96ccef0d468e to your computer and use it in GitHub Desktop.

Select an option

Save mjawaids/072ea7f47f213145b66e96ccef0d468e to your computer and use it in GitHub Desktop.
`newsite` command to create new site in nginx config to be store in /usr/local/bin/newsite
#!/bin/bash
# Usage: sudo newsite project1.local /home/youruser/Sites/project1/public 8081
domain=$1
root=$2
port=${3:-8085}
conf="/etc/nginx/sites-available/$domain"
cat > "$conf" <<EOF
server {
listen $port;
server_name $domain;
root $root;
index index.php index.html;
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
location ~ \.php\$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
access_log /var/log/nginx/${domain}_access.log;
error_log /var/log/nginx/${domain}_error.log;
}
EOF
ln -s "$conf" /etc/nginx/sites-enabled/ 2>/dev/null
nginx -t && systemctl reload nginx
echo "Site $domain created at $root on port $port"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment