App Security with NGINX Balancer
Basic Security for Applications with NGINX Balancer
Before introducing complex or costly application-security tools, several simple protection mechanisms can be applied directly at the NGINX load-balancer layer. This guide covers password authentication, IP-address blocking, and combining both methods.
Security Overview
The NGINX load balancer is primarily used to distribute HTTP and TCP traffic between multiple application servers, improving availability and reliability. It is added automatically when more than one application-server node is selected, and it can also be added manually for a single server from the Balancing section of the topology wizard.

Authentication
Authentication restricts application access so only users with valid credentials can proceed.
- Generate an
htpasswd-compatible hash from the required username and password. Password data should not be stored in plain text. - Return to the dashboard and click Config for the NGINX balancer.

- Inside the
conf.dfolder, create a new file with a.htpasswdextension, for examplepassword.htpasswd.

- Paste the generated credential hash into the file. Add additional accounts on separate lines when required.

- Open
nginx-jelastic.confin theconffolder, find thelocationblock in the firstserversection, and add:
auth_basic "closed site";
auth_basic_user_file /etc/nginx/conf.d/{htpasswd_file};
Replace {htpasswd_file} with the name of the file containing your hashes, for example password.htpasswd.

nginx-jelastic.conf as default/backup configuration and making broader customizations in nginx.conf. For this simple example, it explicitly modifies nginx-jelastic.conf directly.- Save the changes and restart the NGINX balancer.

After restart, opening the application displays an authentication dialog. The application loads only after valid credentials are supplied.

IP Address Deny
If requests from a particular IP address should be blocked, add an NGINX deny rule.
- Open Config for the NGINX balancer.
- Open
nginx-jelastic.conf, locate thelocationblock in the firstserversection, and add:
deny {IP_ADDRESS};
Replace {IP_ADDRESS} with the address that should be blocked.

deny all; blocks everyone. You can combine it with an allow directive to permit a specific IP address or address range.If the simplified deny rule does not work because of a particular platform configuration, the source provides this alternative based on the forwarded client IP header:
if ($http_x_forwarded_for ~* {IP_ADDRESS}) {
return 403;
}
- Save the configuration and restart NGINX.
- A user connecting from the denied IP address receives a 403 Forbidden response.


Methods Combination
Authentication and IP restrictions can be used together with the NGINX satisfy directive.
For example, with satisfy any, an unauthenticated user can still access the application if their IP is explicitly allowed. Likewise, a user from an otherwise denied IP can access the application after providing valid credentials.

Expected Result
NGINX protects the application at the frontend layer by requiring credentials, blocking selected IP addresses, or enforcing both policies according to the configured satisfy behavior.
Important Notes
- Store passwords as hashes rather than plain text.
- Place credential hashes in a
.htpasswdfile underconf.d. - Use
auth_basicandauth_basic_user_filefor password protection. - Use
denyto block a specific IP ordeny allwithallowfor an allowlist approach. - The alternative
$http_x_forwarded_forrule is intended for platform setups where the simple IP-deny rule does not match the real client address. - Restart NGINX after changing these security settings.
