From 71e69e1cfb4b2022d4005d93287aece594894fff Mon Sep 17 00:00:00 2001 From: Wesley Edwards Date: Mon, 9 Nov 2026 19:48:43 -0700 Subject: [PATCH] single ec2 deploy script fix --- .../aws/ec2/TerraformAwsSingleEc2Builder.kt | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/deploy-aws-ec2/src/main/kotlin/com/lightningkite/lightningserver/terraform/aws/ec2/TerraformAwsSingleEc2Builder.kt b/deploy-aws-ec2/src/main/kotlin/com/lightningkite/lightningserver/terraform/aws/ec2/TerraformAwsSingleEc2Builder.kt index a624b1284..cb10528e1 100644 --- a/deploy-aws-ec2/src/main/kotlin/com/lightningkite/lightningserver/terraform/aws/ec2/TerraformAwsSingleEc2Builder.kt +++ b/deploy-aws-ec2/src/main/kotlin/com/lightningkite/lightningserver/terraform/aws/ec2/TerraformAwsSingleEc2Builder.kt @@ -60,7 +60,11 @@ public abstract class TerraformAwsSingleEc2Builder( privateSubnets = TerraformJsonObject.expression("module.vpc.private_subnets"), publicSubnets = TerraformJsonObject.expression("module.vpc.public_subnets"), applicationRouteTables = TerraformJsonObject.expression("module.vpc.public_route_table_ids"), - natGatewayIps = TerraformJsonObject.expression("module.vpc.nat_public_ips"), + // Claude: the instance sits in a public subnet, so it reaches the internet as its Elastic IP, not + // through the NAT. Services allowlist these IPs (e.g. the MongoDB Atlas access list). + natGatewayIps = TerraformJsonObject.expression( + if (enableIPv4) "[aws_eip.main.public_ip]" else "module.vpc.nat_public_ips" + ), ) /** @@ -774,21 +778,8 @@ rm -rf aws/ awscliv2.zip ) } - /** - * The `server` blocks for [domain]: a catch-all that drops unknown hosts, an HTTP-to-HTTPS redirect, - * and the TLS proxy to the app. - */ + /** The `server` blocks for [domain]: an HTTP-to-HTTPS redirect and the TLS proxy to the app. */ private fun nginxServers(domain: String, includeUpgrade: Boolean): String = $$""" -# Drop requests for any other host name or a bare IP -server { - listen 80 default_server; - listen [::]:80 default_server; - listen 443 ssl default_server; - listen [::]:443 ssl default_server; - ssl_reject_handshake on; - return 444; -} - # HTTP: redirect to HTTPS (nginx-module-acme answers ACME challenges before this) server { listen 80; @@ -905,6 +896,16 @@ acme_issuer letsencrypt { state_path /var/cache/nginx/acme-letsencrypt; accept_terms_of_service; } + +# Drop requests for any other host name or a bare IP. nginx allows only one default_server per port. +server { + listen 80 default_server; + listen [::]:80 default_server; + listen 443 ssl default_server; + listen [::]:443 ssl default_server; + ssl_reject_handshake on; + return 444; +} $${nginxServers(domain, wsDomain == domain)} $${if (wsDomain != domain) nginxServers(wsDomain, true) else ""} NGX_EOF