diff --git a/scripts/nym-node-setup/setup-nginx-proxy-wss.sh b/scripts/nym-node-setup/setup-nginx-proxy-wss.sh index b72cf6ed24..cf1378f5b6 100644 --- a/scripts/nym-node-setup/setup-nginx-proxy-wss.sh +++ b/scripts/nym-node-setup/setup-nginx-proxy-wss.sh @@ -23,50 +23,28 @@ SITES_AVAIL="/etc/nginx/sites-available" SITES_EN="/etc/nginx/sites-enabled" HTTP_CONF="${SITES_AVAIL}/${HOSTNAME}" -HTTPS_CONF="${SITES_AVAIL}/${HOSTNAME}-ssl" WSS_CONF="${SITES_AVAIL}/wss-config-nym" echo -echo "* * * Starting clean nginx configuration for landing page, reverse proxy and wss * * *" - -################################################################################ -# step 1: clean all previous configs -################################################################################ - -echo "cleaning existing nginx configuration" - -# remove default nginx config -[[ -L "${SITES_EN}/default" ]] && unlink "${SITES_EN}/default" || true - -# remove domain symlinks -rm -f "${SITES_EN}/${HOSTNAME}" || true -rm -f "${SITES_EN}/${HOSTNAME}-ssl" || true -rm -f "${SITES_EN}/wss-config-nym" || true - -# remove old configs -rm -f "${HTTP_CONF}" || true -rm -f "${HTTPS_CONF}" || true -rm -f "${WSS_CONF}" || true +echo "* * * Starting nginx configuration for landing page, reverse proxy and WSS * * *" ############################################################################### -# step 2: create landing page +# step 1: ensure landing page exists (local fetch -> github -> template) ############################################################################### mkdir -p "${WEBROOT}" -# script directory where Python CLI stores fetched scripts SCRIPT_DIR="$(dirname "${ENV_FILE:-./env.sh}")" LOCAL_FETCHED_PAGE="${SCRIPT_DIR}/landing-page.html" if [[ -s "${LOCAL_FETCHED_PAGE}" ]]; then cp "${LOCAL_FETCHED_PAGE}" "${WEBROOT}/index.html" +elif curl -fsSL \ + https://raw.githubusercontent.com/nymtech/nym/develop/scripts/nym-node-setup/landing-page.html \ + -o "${WEBROOT}/index.html"; then + : else - if curl -fsSL \ - https://raw.githubusercontent.com/nymtech/nym/develop/scripts/nym-node-setup/landing-page.html \ - -o "${WEBROOT}/index.html"; then - : - else - cat > "${WEBROOT}/index.html" < "${WEBROOT}/index.html" < nym node @@ -77,16 +55,35 @@ else EOF - fi fi -echo "landing page at ${WEBROOT}/index.html" +echo "Landing page at ${WEBROOT}/index.html" -echo "landing page at ${WEBROOT}/index.html" +############################################################################### +# step 2: remove default site and old configs, restart nginx +############################################################################### -################################################################################ -# step 3: HTTP :80 config -################################################################################ +echo "Cleaning existing nginx configuration" + +# remove default nginx site +[[ -L "${SITES_EN}/default" ]] && unlink "${SITES_EN}/default" || true + +# optional: remove default available config if present +rm -f /etc/nginx/sites-available/default || true + +# remove old vhosts for this domain +rm -f "${SITES_EN}/${HOSTNAME}" || true +rm -f "${SITES_EN}/${HOSTNAME}-ssl" || true +rm -f "${SITES_EN}/wss-config-nym" || true + +rm -f "${HTTP_CONF}" || true +rm -f "${WSS_CONF}" || true + +systemctl restart nginx || systemctl start nginx + +############################################################################### +# step 3: create basic HTTP config like manual flow (80 -> 8080) +############################################################################### cat > "${HTTP_CONF}" </dev/null 2>&1 || true apt-get install -y certbot python3-certbot-nginx >/dev/null 2>&1 || true -echo "requesting let's encrypt certificate for ${HOSTNAME}" +echo "Requesting Let's Encrypt certificate for ${HOSTNAME}" -certbot --nginx --non-interactive --agree-tos \ - --reuse-key \ - -m "${EMAIL}" -d "${HOSTNAME}" --redirect || true +certbot --nginx --non-interactive --agree-tos --redirect --reuse-key \ + -m "${EMAIL}" -d "${HOSTNAME}" || true -################################################################################ -# step 5: HTTPS and WSS configs -################################################################################ +############################################################################### +# step 5: create WSS 9001 config using certbot-generated certs +############################################################################### if [[ -s "/etc/letsencrypt/live/${HOSTNAME}/fullchain.pem" ]]; then - echo "certificate detected, creating https and wss configs" + echo "Certificate detected, creating WSS config" - # HTTPS 443 - cat > "${HTTPS_CONF}" < "${WSS_CONF}" <