Last active
December 15, 2016 11:36
-
-
Save asabirov/5d16a1fd920529422546 to your computer and use it in GitHub Desktop.
Generates Nginx configuration for vhost with PHP-FPM support
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
echo Please, enter domain name: | |
read DOMAIN_NAME | |
echo Please, enter domain IP: | |
read SERVER_IP | |
echo Please, enter domain directory: | |
read DOMAIN_DIR | |
echo "Please, enter Nginx config directory (default /etc/nginx/conf.d):" | |
read CONFIG_DIR | |
echo "Please, enter socket path (default /var/run/php7-fpm.sock):" | |
read SOCKET_PATH | |
CONFIG_DIR=${CONFIG_DIR:-/etc/nginx/conf.d} | |
SOCKET_PATH=${SOCKET_PATH:-/var/run/php7-fpm.sock} | |
CONFIG_CONTENT="server { | |
# server IP and port | |
listen ${SERVER_IP}:80; | |
# domain name | |
server_name ${DOMAIN_NAME} www.${DOMAIN_NAME}; | |
# root path | |
set \$root_path ${DOMAIN_DIR}; | |
root \$root_path; | |
charset utf-8; | |
index index.php; | |
include /etc/nginx/vhosts-includes/*.conf; | |
location ~* \.(jpg|jpeg|gif|png|js|css|txt|zip|ico|gz|csv)\$ { | |
access_log off; | |
expires 10d; | |
} | |
location ~* /(var|lib|application)/.*\$ { | |
return 403; | |
} | |
location ~* \.(htaccess|ini|dat)\$ { | |
return 403; | |
} | |
location ~ \.php\$ { | |
include /etc/nginx/fastcgi_params; | |
fastcgi_pass unix:${SOCKET_PATH}; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME \$root_path\$fastcgi_script_name; | |
} | |
location / { | |
try_files \$uri \$uri/ /index.php?\$args; | |
} | |
}" | |
echo "$CONFIG_CONTENT" > "/${CONFIG_DIR}/${DOMAIN_NAME}.conf" | |
echo "File ${CONFIG_DIR}/${DOMAIN_NAME}.conf created!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment