It seems like the issue you're facing is related to the nginx configuration not properly handling requests for subdomains other than the one explicitly defined. Let's go through your configuration and make some adjustments:
Default Server Configuration:
The default server configuration should only handle requests for domains/subdomains that are not explicitly defined in other server blocks. Ensure that this configuration is set up to return a 404 error for such requests.
Explicit Server Configurations for Each Subdomain:
Each subdomain should have its own server block where you define the proxy_pass directive to forward requests to the appropriate backend server. Make sure that each server block listens on port 80 and 443 for both IPv4 and IPv6 if needed.
Here's a revised version of your nginx configuration:
In this configuration:
The default server block listens for requests to undefined subdomains and returns a 404 error.
Each subdomain has its own server block, which listens for requests to that specific subdomain and proxies them accordingly.
Make sure to adjust the SSL certificate paths and other settings as per your environment. After making these changes, reload nginx for the configuration to take effect.
Default Server Configuration:
The default server configuration should only handle requests for domains/subdomains that are not explicitly defined in other server blocks. Ensure that this configuration is set up to return a 404 error for such requests.
Explicit Server Configurations for Each Subdomain:
Each subdomain should have its own server block where you define the proxy_pass directive to forward requests to the appropriate backend server. Make sure that each server block listens on port 80 and 443 for both IPv4 and IPv6 if needed.
Here's a revised version of your nginx configuration:
Code:
# Default server configurationserver { listen 80 default_server; listen [::]:80 default_server; listen 443 ssl default_server; listen [::]:443 ssl default_server; server_name _; ssl_certificate /var/www/live/certificate.crt; ssl_certificate_key /var/www/live/certificate.key; ssl_trusted_certificate /var/www/live/certificate.bundle.crt; return 404;}# Subdomain 1 configurationserver { listen 80; listen [::]:80; listen 443 ssl; listen [::]:443 ssl; server_name sub1.domain.com; ssl_certificate /var/www/live/certificate.crt; ssl_certificate_key /var/www/live/certificate.key; ssl_trusted_certificate /var/www/live/certificate.bundle.crt; location / { proxy_buffering off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; proxy_pass https://sub1.domain.com:443; }}# Subdomain 2 configurationserver { listen 80; listen [::]:80; listen 443 ssl; listen [::]:443 ssl; server_name sub2.domain.com; ssl_certificate /var/www/live/certificate.crt; ssl_certificate_key /var/www/live/certificate.key; ssl_trusted_certificate /var/www/live/certificate.bundle.crt; location / { proxy_buffering off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; proxy_pass https://sub2.domain.com:443; }}
The default server block listens for requests to undefined subdomains and returns a 404 error.
Each subdomain has its own server block, which listens for requests to that specific subdomain and proxies them accordingly.
Make sure to adjust the SSL certificate paths and other settings as per your environment. After making these changes, reload nginx for the configuration to take effect.
Statistics: Posted by andrea924breaux — 2024-03-15 09:05