Copy & Paste
__FILE_DIR__="$HOME/__TMP_CREATE_NGINX_CONF__.sh"
sudo mkdir -p $(dirname ${__FILE_DIR__}) \\
&& sudo touch ${__FILE_DIR__} && sudo chmod 757 ${__FILE_DIR__} && cat << 'EOF' > ${__FILE_DIR__}
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 사용자 입력
read -p "Port(From): " PORT_FROM
read -p "Port(To) : " PORT_TO
read -p "Domain : " DOMAIN_NAME
CONF_DIR="/etc/nginx/sites-available/rdt_ssl_${PORT_FROM}_${PORT_TO}.conf"
sudo touch $CONF_DIR
sudo chmod 777 $CONF_DIR
echo "server {" > ${CONF_DIR}
echo " listen ${PORT_FROM} ssl;" >> ${CONF_DIR}
echo " listen [::]:${PORT_FROM} ssl;" >> ${CONF_DIR}
echo "" >> ${CONF_DIR}
echo " server_name ${DOMAIN_NAME} ;" >> ${CONF_DIR}
echo " ssl_certificate /etc/letsencrypt/live/${DOMAIN_NAME}/fullchain.pem;" >> ${CONF_DIR}
echo " ssl_certificate_key /etc/letsencrypt/live/${DOMAIN_NAME}/privkey.pem;" >> ${CONF_DIR}
echo " include /etc/letsencrypt/options-ssl-nginx.conf;" >> ${CONF_DIR}
echo " ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;" >> ${CONF_DIR}
echo "" >> ${CONF_DIR}
echo " location / {" >> ${CONF_DIR}
echo " proxy_pass <http://127.0.0.1>:${PORT_TO};" >> ${CONF_DIR}
echo " proxy_set_header X-Real-IP \\$remote_addr;" >> ${CONF_DIR}
echo " proxy_set_header X-Forwarded-For \\$proxy_add_x_forwarded_for;" >> ${CONF_DIR}
echo " proxy_set_header Host \\$http_host;" >> ${CONF_DIR}
echo " }" >> ${CONF_DIR}
echo "}" >> ${CONF_DIR}
sudo chmod 755 $CONF_DIR
sudo ln -s ${CONF_DIR} /etc/nginx/sites-enabled/
sudo service nginx reload
sudo rm ${__FILE_DIR__}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EOF
export __FILE_DIR__ && bash -c "${__FILE_DIR__}"