Created
July 16, 2010 19:05
-
-
Save carlosjac/478779 to your computer and use it in GitHub Desktop.
NginxCreateVirtualDomain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Create a virtual domain on Nginx Ubuntu 10.04 (Slicehost) | |
# Execute as root | |
# | |
# Author : Carlos Jacobs | |
# Date : 16 Jul 2010 | |
echo Please, enter domain | |
read DOMAIN | |
sudo mkdir /tmp/cert | |
sudo cd /tmp/cert | |
sudo openssl req -new -nodes -keyout $DOMAIN.key -out $DOMAIN.csr | |
sudo openssl x509 -req -days 3650 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt | |
sudo cp $DOMAIN.crt /etc/ssl/certs/ | |
sudo cp $DOMAIN.key /etc/ssl/private/ | |
sudo rm * | |
mkdir -p /var/www/$DOMAIN/public_html | |
mkdir /var/www/$DOMAIN/logs | |
chown -R www-data:www-data /var/www/$DOMAIN | |
echo "server { | |
listen 80; | |
server_name www.$DOMAIN $DOMAIN; | |
access_log /var/www/$DOMAIN/logs/access.log; | |
error_log /var/www/$DOMAIN/logs/error.log; | |
location / { | |
root /var/www/$DOMAIN/public_html; | |
index index.html index.htm index.php; | |
} | |
location ~ \.php$ { | |
include /etc/nginx/fastcgi_params; | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /var/www/$DOMAIN/public_html\$fastcgi_script_name; | |
fastcgi_connect_timeout 60; | |
fastcgi_send_timeout 180; | |
fastcgi_read_timeout 180; | |
fastcgi_buffer_size 128k; | |
fastcgi_buffers 4 256k; | |
fastcgi_busy_buffers_size 256k; | |
fastcgi_temp_file_write_size 256k; | |
fastcgi_intercept_errors on; | |
} | |
} | |
server { | |
listen 443; | |
ssl on; | |
ssl_certificate /etc/ssl/certs/$DOMAIN.crt; | |
ssl_certificate_key /etc/ssl/private/$DOMAIN.key; | |
server_name www.$DOMAIN $DOMAIN; | |
access_log /var/www/$DOMAIN/logs/access.log; | |
error_log /var/www/$DOMAIN/logs/error.log; | |
location / { | |
root /var/www/$DOMAIN/public_html; | |
index index.html index.htm index.php; | |
} | |
location ~ \.php$ { | |
include /etc/nginx/fastcgi_params; | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /var/www/$DOMAIN/public_html\$fastcgi_script_name; | |
fastcgi_connect_timeout 60; | |
fastcgi_send_timeout 180; | |
fastcgi_read_timeout 180; | |
fastcgi_buffer_size 128k; | |
fastcgi_buffers 4 256k; | |
fastcgi_busy_buffers_size 256k; | |
fastcgi_temp_file_write_size 256k; | |
fastcgi_intercept_errors on; | |
} | |
} | |
" > /etc/nginx/sites-available/$DOMAIN | |
cd /etc/nginx/sites-enabled/ | |
ln -s /etc/nginx/sites-available/$DOMAIN | |
/etc/init.d/nginx restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment