Last active
July 22, 2018 04:47
-
-
Save cucxabeng/ee05b4b442cfe2e9fa9b0c4c8d750206 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment