One IP serve two websites running by nginx

I have two websites. Each of them is running on a Ubuntu Server and is deployed by docker-compose. Each docker-compose includes a nginx service. I set up my web server by this cool tutorial.
Here is an example of how I configure nginx.

server {
    listen      80;
    listen [::]:80;
    server_name ohhaithere.com www.ohhaithere.com;

    location / {
        rewrite ^ https://$host$request_uri? permanent;
    }

    #for certbot challenges (renewal process)
    location ~ /.well-known/acme-challenge {
        allow all;
        root /data/letsencrypt;
    }
}

#https://ohhaithere.com
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ohhaithere.com;

    server_tokens off;

    ssl_certificate /etc/letsencrypt/live/ohhaithere.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ohhaithere.com/privkey.pem;

    ssl_buffer_size 8k;

    ssl_dhparam /etc/ssl/certs/dhparam-2048.pem;

    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
    ssl_prefer_server_ciphers on;

    ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;

    ssl_ecdh_curve secp384r1;
    ssl_session_tickets off;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8;

    return 301 https://www.ohhaithere.com$request_uri;
}

#https://www.ohhaithere.com
server {
    server_name www.ohhaithere.com;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_tokens off;

    ssl on;

    ssl_buffer_size 8k;
    ssl_dhparam /etc/ssl/certs/dhparam-2048.pem;

    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;

    ssl_ecdh_curve secp384r1;
    ssl_session_tickets off;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8 8.8.4.4;

    ssl_certificate /etc/letsencrypt/live/ohhaithere.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ohhaithere.com/privkey.pem;

    root /usr/share/nginx/html;
    index index.html;
}

Each of my website can run smoothly. But the problem is I only have one ip. I cannot run both websites at the same time since I cannot run two nginx to listen same port either 80 or 443.

But I don’t want to mix to websites up and run on nginx. So I plan to run another nginx listening 80 or 443. And according to the domain name, this nginx direct to different port. I searched on website quite a time. I found this Automated nginx proxy for Docker containers using docker-gen. I am not sure it is worth to use it for a not complex problem.

So I let my websites run on the same network.

version: '3.5'

services:
  nginx-proxy:
    build:
      context: .
      dockerfile: docker/nginx/Dockerfile

    ports:
      - 80:80
      - 443:443
    networks:
      - networkabc
networks:
  networkabc:
    driver: bridge

But I do not know how to do in configure file. How to forward the request in a right way. Here is my try but does not work.

server{
    listen 80;
    listen 443

    server_name website1.com www.website1.com;

    location / {
      proxy_pass http://website1.com:4999;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}


server{
    listen 80;
    listen 443

    server_name website2.com www.website2.com;

    location / {
      proxy_pass http://website2.com:5000;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

Suppose website1

ports:
      - 80:4999
      - 443:443 

and website2

ports:
      - 180:5000
      - 1443:443 # https

Source: StackOverflow