I have followed what seems like countless sites on how to set-up a reverse proxy with nginx.
I am going to run several websites in docker containers on an EC2 instance. The instance is in a target group behind an ALB - SSL termination at the ALB.
I have created sites A and B:
sitea.conf
server {
root /var/www/html;
server_name sitea.com;
location / {
proxy_pass http://127.0.0.1:9090;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
siteb.conf
server {
root /var/www/html;
server_name siteb.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
This was a default install of nginx on an AWS Linux 2 AMI.
I put both sitea.conf and siteb.conf in the
/etc/nginx/sites-available
directory and then created the symlink
ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled
What I am expecting is the routing by nginx.
What is happening is sitea.com is getting ALL of the traffic.
Even the load balancer health checks are being routed by nginx to sitea. Tailing the logs on the container
docker logs --follow sitea
I see all of the health check requests coming in (and getting re-directed because it is a wordpress container).
Nginx is not routing any traffic based on the host header (the load balancer health checks being the tell tale indicator).
Obviously something with my configuration - but I thought this was all there was too it. Where else do I need to configure nginx for a multi-site reverse proxy?
EDIT:
Including the /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local]
"$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/sites-enabled/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}