Skip to content

Commit

Permalink
Remove NodeJS support; Introduce NGINX_STATIC_ROOT
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlemke committed Jun 17, 2020
1 parent a34a52b commit 4d24759
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 38 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ tbd.

## Hosting a static website

tbd.
Set the environment variable "BEACH_NGINX_MODE" to "Static" and
optionally set the variable "NGINX_STATIC_ROOT" to the path leading to
the root of your static site.

The BEACH_NGINX_MODE variable follows legacy naming and will be renamed
/ replaced by another concept in the future.

## Configuration

Expand Down Expand Up @@ -53,9 +58,11 @@ for possible values. The default value is `warn`.
| NGINX_CACHE_BACKGROUND_UPDATE | boolean | off | If background updates should be enabled |
| NGINX_CUSTOM_ERROR_PAGE_CODES | string | 500 501 502 503 | FastCGI error codes which should redirect to the custom error page |
| NGINX_CUSTOM_ERROR_PAGE_TARGET | string | | Upstream URL to use for custom FastCGI error pages |
| NGINX_STATIC_ROOT | string | /var/www/html | Document root path for when BEACH_NGINX_MODE is "Static" |
| BEACH_NGINX_CUSTOM_METRICS_ENABLE | boolean | no | If support for a custom metrics endpoint should be enabled |
| BEACH_NGINX_CUSTOM_METRICS_SOURCE_PATH | string | /metrics | Path where metrics are located |
| BEACH_NGINX_CUSTOM_METRICS_TARGET_PORT | integer | 8082 | Port at which Nginx should listen to provide the metrics for scraping |
| BEACH_NGINX_MODE | string | Flow | Either "Flow" or "Static"; this variable is going to be renamed in the future |
| FLOW_HTTP_TRUSTED_PROXIES | string | 10.0.0.0/8 | Nginx passes FLOW_HTTP_TRUSTED_PROXIES to the virtual host using the value of this variable |

## Security aspects
Expand Down
40 changes: 3 additions & 37 deletions root-files/opt/flownative/lib/nginx-legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export BEACH_NGINX_CUSTOM_METRICS_TARGET_PORT=${BEACH_NGINX_CUSTOM_METRICS_TARGE
export NGINX_CUSTOM_ERROR_PAGE_TARGET=${NGINX_CUSTOM_ERROR_PAGE_TARGET:-${BEACH_NGINX_CUSTOM_ERROR_PAGE_TARGET:-}}
export NGINX_UPSTREAM_HOST=${NGINX_UPSTREAM_HOST:-127.0.0.1}
export NGINX_UPSTREAM_PORT=${NGINX_UPSTREAM_PORT:-3000}
export NGINX_STATIC_ROOT=${NGINX_STATIC_ROOT:-/var/www/html}
EOF
}

Expand Down Expand Up @@ -173,50 +172,19 @@ EOM
EOM
}

# ---------------------------------------------------------------------------------------
# nginx_legacy_initialize_nodejs() - Set up Nginx configuration for NodeJS
#
# @global NGINX_* The NGINX_* environment variables
# @return void
#
nginx_legacy_initialize_nodejs() {
info "Nginx: Enabling site configuration for NodeJS ..."
cat >"${NGINX_CONF_PATH}/sites-enabled/nodejs.conf" <<-EOM
upstream nodejs {
server ${NGINX_UPSTREAM_HOST}:${NGINX_UPSTREAM_PORT};
keepalive 8;
}
server {
listen *:8080 default_server;
add_header Via '\$hostname';
location / {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_pass http://nodejs/;
proxy_redirect off;
}
}
EOM
}

# ---------------------------------------------------------------------------------------
# nginx_legacy_initialize_static() - Set up Nginx configuration for a static site
#
# @global NGINX_* The NGINX_* environment variables
# @return void
#
nginx_legacy_initialize_static() {
info "Nginx: Enabling default site configuration ..."
info "Nginx: Enabling static site configuration with root at ${NGINX_STATIC_ROOT} ..."
cat >"${NGINX_CONF_PATH}/sites-enabled/default.conf" <<-EOM
server {
listen *:8080 default_server;
root /var/www/html;
root ${NGINX_STATIC_ROOT};
# deny files starting with a dot (having "/." in the path)
location ~ /\\. {
Expand Down Expand Up @@ -308,8 +276,6 @@ nginx_legacy_initialize() {

if [ "$BEACH_NGINX_MODE" == "Flow" ]; then
nginx_legacy_initialize_flow
elif [ "$BEACH_NGINX_MODE" == "NodeJS" ]; then
nginx_legacy_initialize_nodejs
else
nginx_legacy_initialize_static
fi
Expand Down

0 comments on commit 4d24759

Please sign in to comment.