I am trying to load balance frontend (public) and backend (private) servers in AWS. I got the nginx file working with a single server with IP address, but the loadbalancer DNS name doesn't seem to work, below is my nginx.conf for the frontend server. In the listener section of the loadbalancer the loadbalancer port is 443 and instance port is 9000. Any suggessions greatly appreciated.
WORKING...
server {
listen 80;
rewrite ^(.*) https://example.com$request_uri;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/chain.crt;
ssl_certificate_key /etc/ssl/key.crt;
listen localhost:443;
server_tokens off;
client_max_body_size 300M;
location / {
root /var/www/html;
index index.html index.htm;
}
location /api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://<BackendIP>:9000/api/;
proxy_set_header Host $http_host;
}
}
}
NOT WORKING...
server {
listen 80;
rewrite ^(.*) https://example.com$request_uri;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/chain.crt;
ssl_certificate_key /etc/ssl/key.crt;
listen localhost:443;
server_tokens off;
client_max_body_size 300M;
location / {
root /var/www/html;
index index.html index.htm;
}
location /api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://<LOADBALANCER-DNS>:9000/api/;
proxy_set_header Host $http_host;
}
}
}