|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Define the output file location |
| 4 | +PROXY_PARAMS_FILE="/etc/nginx/proxy_params" |
| 5 | + |
| 6 | +# Backup existing file if it exists |
| 7 | +if [[ -f "$PROXY_PARAMS_FILE" ]]; then |
| 8 | + cp "$PROXY_PARAMS_FILE" "${PROXY_PARAMS_FILE}.bak" |
| 9 | +fi |
| 10 | + |
| 11 | +# Write the proxy parameters to the file |
| 12 | +cat <<EOF > "$PROXY_PARAMS_FILE" |
| 13 | +# Essential Proxy Headers |
| 14 | +proxy_set_header Host \$host; |
| 15 | +proxy_set_header X-Real-IP \$remote_addr; |
| 16 | +proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; |
| 17 | +proxy_set_header X-Forwarded-Proto \$scheme; |
| 18 | +
|
| 19 | +# Forwarding Additional Headers |
| 20 | +proxy_set_header HTTP_CLIENT_IP \$http_client_ip; |
| 21 | +proxy_set_header HTTP_X_FORWARDED_FOR \$http_x_forwarded_for; |
| 22 | +proxy_set_header HTTP_CF_CONNECTING_IP \$http_cf_connecting_ip; |
| 23 | +proxy_set_header HTTP_FASTLY_CLIENT_IP \$http_fastly_client_ip; |
| 24 | +proxy_set_header HTTP_TRUE_CLIENT_IP \$http_true_client_ip; |
| 25 | +proxy_set_header HTTP_AKAMAI_EDGE_CLIENT_IP \$http_akamai_edge_client_ip; |
| 26 | +proxy_set_header HTTP_X_AZURE_CLIENTIP \$http_x_azure_clientip; |
| 27 | +proxy_set_header HTTP_X_APPENGINE_USER_IP \$http_x_appengine_user_ip; |
| 28 | +proxy_set_header HTTP_X_REAL_IP \$http_x_real_ip; |
| 29 | +proxy_set_header HTTP_X_CLUSTER_CLIENT_IP \$http_x_cluster_client_ip; |
| 30 | +proxy_set_header HTTP_ALI_CLIENT_IP \$http_ali_client_ip; |
| 31 | +proxy_set_header HTTP_X_ORACLE_CLIENT_IP \$http_x_oracle_client_ip; |
| 32 | +proxy_set_header HTTP_X_STACKPATH_EDGE_IP \$http_x_stackpath_edge_ip; |
| 33 | +proxy_set_header HTTP_USER_AGENT \$http_user_agent; |
| 34 | +proxy_set_header HTTP_ACCEPT \$http_accept; |
| 35 | +proxy_set_header HTTP_ACCEPT_LANGUAGE \$http_accept_language; |
| 36 | +proxy_set_header HTTP_REFERER \$http_referer; |
| 37 | +
|
| 38 | +# Essential Server Headers |
| 39 | +proxy_set_header SERVER_ADDR \$server_addr; |
| 40 | +proxy_set_header SERVER_PORT \$server_port; |
| 41 | +proxy_set_header SERVER_NAME \$server_name; |
| 42 | +proxy_set_header REMOTE_ADDR \$remote_addr; |
| 43 | +proxy_set_header REMOTE_PORT \$remote_port; |
| 44 | +proxy_set_header REMOTE_USER \$remote_user; |
| 45 | +EOF |
| 46 | + |
| 47 | +# Display confirmation message |
| 48 | +echo "✅ Proxy parameters successfully written to $PROXY_PARAMS_FILE" |
| 49 | +rm -f -- "$0" |
0 commit comments