Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# -eq 0 ]
- then
- echo "No arguments supplied"
- exit 1
- fi
- domain=$1
- root="/home/forge/$domain"
- block="/etc/nginx/sites-available/$domain"
- # Create the Document Root directory
- sudo mkdir -p $root
- # Assign ownership to your regular user account
- sudo chown -R $USER:$USER $root
- # Create the Nginx server block file:
- sudo tee $block > /dev/null <<EOF
- server {
- listen 80;
- server_name $domain www.$domain;
- root /home/forge/$domain/public;
- index index.html index.htm index.php;
- charset utf-8;
- location / {
- try_files \$uri \$uri/ /index.php?\$query_string;
- }
- location = /favicon.ico { access_log off; log_not_found off; }
- location = /robots.txt { access_log off; log_not_found off; }
- access_log off;
- error_log /var/log/nginx/$domain-error.log error;
- sendfile off;
- client_max_body_size 100m;
- location ~ \.php$ {
- fastcgi_split_path_info ^(.+\.php)(/.+)$;
- fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
- fastcgi_index index.php;
- include fastcgi_params;
- fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
- fastcgi_intercept_errors off;
- fastcgi_buffer_size 16k;
- fastcgi_buffers 4 16k;
- }
- #browser caching of static assets
- location ~* \.(jpg|jpeg|png|gif|ico)$ {
- expires 7d;
- }
- #browser caching of css and js
- location ~* \.(css|js)$ {
- expires 7d;
- }
- location ~ /\.ht {
- deny all;
- }
- }
- EOF
- # Link to make it available
- sudo ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
- # Test configuration and reload if successful
- sudo nginx -t && sudo service nginx reload
Add Comment
Please, Sign In to add comment