title: ec2 instance and load balancer reverse proxy Nginx
body: <p>I am a bit confused about the Nginx configuration when it come to a load balancer.</p>
  <p>This is my situation.</p>
  <p>On aws I have a load balancer to control the traffic of 2 ec2 instances.</p>
  <p>the default configuration of Nginx works just fine, in fact if I open directly the ec2 instances IP in my browser I see the nginx page. Same if I hit the load balancer dns name I see the nginx default page.</p>
  <p>For demonstration purpose. I configured my nginx.conf as follow:</p>
  <pre><code>server {
      listen   80; ## listen for ipv4; this line is default and implied
      listen vm-ip:80;
  
      server_name vm-ip;
  
      root /usr/share/nginx/html;
      index index.html;
  
      server_tokens  off; # disable the Server nginx header 
  
      # enable gzip
      gzip on;
      gzip_disable &quot;msie6&quot;;
  
      gzip_comp_level 6;
      gzip_min_length 1100;
      gzip_buffers 16 8k;
      gzip_proxied any;
      gzip_types
          text/plain
          text/css
          text/js
          text/xml
          text/javascript
          application/javascript
          application/x-javascript
          application/json
          application/xml
          application/rss+xml
          image/svg+xml;
  
      location / {
          # try_files $uri /index.html; # redirect all request to index.html
          proxy_pass https://&lt;dns of website I want to be redirected to&gt;;
  
      }
  }
  </code></pre>
  <p>I set the same nginx.conf for both ec2 instances. After this configuration I tried to hit the ip of the ec2 instance directly and I was redirected correctly to the website I wanted. But here is the problem, when I try to do the same opening the load balancer in my browser, I still see the nginx default page.</p>
  <p>Can anyone explain me please what am I doing wrong here?</p>
  <p>and please if my question is not clear enough, just ask me more info and I will be more than happy to provide an answer.</p>
  <p>Thank you so much in advance</p>