Last active
November 25, 2019 19:17
-
-
Save RafikFarhad/a673027ea8166e730e2eaf74bb12ddc6 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 | |
<<ReadMe | |
Author: Rafik Farhad <rafikfarhad@gmail.com> | |
Run: bash sudo <script.sh> | |
ReadMe | |
if [[ $(id -u) -ne 0 ]]; then | |
echo "Please run as root" | |
exit ; | |
fi | |
read -r -p 'Project Name: ' project_name | |
read -r -p 'Project Path (without trailing slash /) : ' path | |
read -r -p 'Local Domain : ' domain | |
FILE=/etc/nginx/sites-enabled/$domain.conf | |
sudo cat > $FILE << EOF | |
server { | |
listen 80; | |
#listen [::]:80; | |
root $path/public; | |
index index.php index.html; | |
server_name $domain; | |
location / { | |
try_files $uri \$uri/ /index.php?\$query_string; | |
} | |
location ~* \.(jpg|jpeg|gif|png|ico|html|pdf|xml|txt)$ { | |
access_log off; | |
expires max; | |
log_not_found off; | |
add_header Cache-Control "public"; | |
} | |
location ~ \.php$ { | |
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi.conf; | |
} | |
location ~* \.(?:css|js|ttf|woff|woff2)$ { | |
expires 1d; | |
access_log off; | |
add_header Cache-Control "public"; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
} | |
EOF | |
echo "Conf File Created: " $FILE | |
sudo echo '127.0.0.1 '$domain >> /etc/hosts | |
echo "/etc/hosts Updated" | |
sudo nginx -t | |
sudo systemctl reload nginx | |
echo "NGINX Reloaded" | |
sudo systemctl restart nginx | |
echo "NGINX Restarted" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment