0
votes

I am trying to deploy a very simple proxy that will listen HTTP on port 80 and forward (not to return redirect 301!!) to HTTPS on port 433 on external host.

I am using clear Elastic Beanstalk instance with uploading of just the following config for nginx (by https://docs.nginx.com/nginx/admin-guide/security-controls/securing-http-traffic-upstream/):

files:
  /etc/nginx/conf.d/proxy.conf:
    mode: "000644"
    owner: root
    group: root
    content: |
      upstream backend {
        server xxxxxx.execute-api.xx-xx-x.amazonaws.com:443;
      }

      server {
        listen 80;
        servername blablabla.eba-smthng.xx-xx-x.elasticbeanstalk.com;

        if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
            set $year $1;
            set $month $2;
            set $day $3;
            set $hour $4;
        }
        access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
        access_log /var/log/nginx/access.log  main;

        location / {
            proxy_pass https://backend;
        }

      }

  /opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash -xe
      rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
      service nginx stop 
      service nginx start

container_commands:
  removeconfig:
    command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"

And I expect that all HTTP requests to blablabla.eba-smthng.xx-xx-x.elasticbeanstalk.com will be proxied to HTTPS endpoint xxxxxx.execute-api.xx-xx-x.amazonaws.com.

But what I getting is always:

$ curl -X POST http://blablabla.eba-smthng.xx-xx-x.elasticbeanstalk.com/some/resource -d "{}"

<html>
<head><title>302 Found</title></head>
<body>
<center><h1>302 Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>

What's wrong?

1

1 Answers

0
votes

OK, I solved this without Beantalks - just by using EC2 instance with nginx only.

Config is very simple, and I suspect it should work in Beantalks as well:

      server {
        listen 80;
        server_name blablabla.eba-smthng.xx-xx-x.elasticbeanstalk.com;

        location / {

            proxy_pass https://xxxxxx.execute-api.xx-xx-x.amazonaws.com:443/;
            proxy_ssl_session_reuse on;
        }

      }

It's important to keep closing slashes, and there is no need for rewrites and headers if proxy_pass has URI argument. In my initial post was used wrong token servername - has to be server_name.