Skip to content

Instantly share code, notes, and snippets.

@huglester
Created September 8, 2014 15:09
Show Gist options
  • Save huglester/3a9b110b7ec3c2ac9f65 to your computer and use it in GitHub Desktop.
Save huglester/3a9b110b7ec3c2ac9f65 to your computer and use it in GitHub Desktop.
vhost_add.sh
#!/usr/bin/env bash
if [[ -z "$1" ]]; then
echo "example usage: /usr/local/bin/vhost_add.sh acme";
exit;
fi
block="server {
server_name $1.avek.eu;
root /var/www/vhosts/$1/web;
charset utf-8;
etag off;
client_max_body_size 600m;
include global/restrictions.conf;
#Add cache expire to these files
location ^~ /media/ {
location ~* (\.jpg|\.jpeg|\.png|\.gif|\.ico)\$ {
access_log off;
log_not_found off;
expires 30d;
# try to serve file directly, fallback to rewrite
try_files \$uri @rewriteapp;
}
}
location ^~ /bundles/ {
location ~* (\.jpg|\.jpeg|\.png|\.css|\.js|\.gif|\.ico)\$ {
access_log off;
log_not_found off;
expires 30d;
# try to serve file directly, fallback to rewrite
try_files \$uri @rewriteapp;
}
}
location ^~ /css/ {
location ~* (\.css)\$ {
access_log off;
log_not_found off;
expires 30d;
# try to serve file directly, fallback to rewrite
try_files \$uri @rewriteapp;
}
}
location ^~ /js/ {
location ~* (\.js)\$ {
access_log off;
log_not_found off;
expires 30d;
# try to serve file directly, fallback to rewrite
try_files \$uri @rewriteapp;
}
}
location / {
# try to serve file directly, fallback to rewrite
try_files \$uri @rewriteapp;
}
location @rewriteapp {
# rewrite all to app.php
rewrite ^(.*)\$ /app.php/\$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|\$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)\$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param HTTPS off;
# php timeout to 1min
fastcgi_read_timeout 60;
expires epoch;
fastcgi_cache_valid 200 302 60m;
fastcgi_cache_valid 301 1h;
fastcgi_cache_valid any 1m;
# http://stackoverflow.com/questions/17708152/nginx-overwrites-general-symfony-errors-with-502-bad-gateway
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
access_log /var/log/nginx/$1-access.log;
error_log /var/log/nginx/$1-error.log info;
}"
echo "$block" > "/etc/nginx/sites-available/$1"
ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
mkdir -p /var/www/vhosts/$1
chown -R www-data:www-data /var/www/vhosts/$1
service nginx restart
#service php5-fpm restart
killall -9 php5-fpm
sleep 1
service php5-fpm start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment