authserver/homestead/scripts/serve.sh
changeset 8 5a0cbbe0922a
equal deleted inserted replaced
7:1a3fa80225b2 8:5a0cbbe0922a
       
     1 #!/usr/bin/env bash
       
     2 
       
     3 mkdir /etc/nginx/ssl 2>/dev/null
       
     4 openssl genrsa -out "/etc/nginx/ssl/$1.key" 1024 2>/dev/null
       
     5 openssl req -new -key /etc/nginx/ssl/$1.key -out /etc/nginx/ssl/$1.csr -subj "/CN=$1/O=Vagrant/C=UK" 2>/dev/null
       
     6 openssl x509 -req -days 365 -in /etc/nginx/ssl/$1.csr -signkey /etc/nginx/ssl/$1.key -out /etc/nginx/ssl/$1.crt 2>/dev/null
       
     7 
       
     8 block="server {
       
     9     listen ${3:-80};
       
    10     server_name $1;
       
    11     root \"$2\";
       
    12 
       
    13     index index.html index.htm index.php;
       
    14 
       
    15     charset utf-8;
       
    16 
       
    17     location / {
       
    18         try_files \$uri \$uri/ /index.php?\$query_string;
       
    19     }
       
    20 
       
    21     location = /favicon.ico { access_log off; log_not_found off; }
       
    22     location = /robots.txt  { access_log off; log_not_found off; }
       
    23 
       
    24     access_log off;
       
    25     error_log  /var/log/nginx/$1-error.log error;
       
    26 
       
    27     sendfile off;
       
    28 
       
    29     client_max_body_size 100m;
       
    30 
       
    31     location ~ \.php$ {
       
    32         fastcgi_split_path_info ^(.+\.php)(/.+)$;
       
    33         fastcgi_pass unix:/var/run/php5-fpm.sock;
       
    34         fastcgi_index index.php;
       
    35         include fastcgi_params;
       
    36         fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
       
    37         fastcgi_intercept_errors off;
       
    38         fastcgi_buffer_size 16k;
       
    39         fastcgi_buffers 4 16k;
       
    40     }
       
    41 
       
    42     location ~ /\.ht {
       
    43         deny all;
       
    44     }
       
    45 }
       
    46 server {
       
    47     listen ${4:-443};
       
    48     server_name $1;
       
    49     root \"$2\";
       
    50 
       
    51     index index.html index.htm index.php;
       
    52 
       
    53     charset utf-8;
       
    54 
       
    55     location / {
       
    56         try_files \$uri \$uri/ /index.php?\$query_string;
       
    57     }
       
    58 
       
    59     location = /favicon.ico { access_log off; log_not_found off; }
       
    60     location = /robots.txt  { access_log off; log_not_found off; }
       
    61 
       
    62     access_log off;
       
    63     error_log  /var/log/nginx/$1-ssl-error.log error;
       
    64 
       
    65     sendfile off;
       
    66 
       
    67     client_max_body_size 100m;
       
    68 
       
    69     location ~ \.php$ {
       
    70         fastcgi_split_path_info ^(.+\.php)(/.+)$;
       
    71         fastcgi_pass unix:/var/run/php5-fpm.sock;
       
    72         fastcgi_index index.php;
       
    73         include fastcgi_params;
       
    74         fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
       
    75         fastcgi_intercept_errors off;
       
    76         fastcgi_buffer_size 16k;
       
    77         fastcgi_buffers 4 16k;
       
    78     }
       
    79 
       
    80     location ~ /\.ht {
       
    81         deny all;
       
    82     }
       
    83 
       
    84     ssl on;
       
    85     ssl_certificate     /etc/nginx/ssl/$1.crt;
       
    86     ssl_certificate_key /etc/nginx/ssl/$1.key;
       
    87 }
       
    88 "
       
    89 
       
    90 echo "$block" > "/etc/nginx/sites-available/$1"
       
    91 ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
       
    92 service nginx restart
       
    93 service php5-fpm restart