0

I am making web app using Docker, and nginx as reverse proxy. I have problem with custom port in docker. I would like to redirect user who use HTTP:// instead of HTTPS:// using only one port.

It's like http://app.aufy.pl:38000, user should be redirected to https://app.aufy.pl:38000 to not get HTTP Error 400.

Typically people would use port 80 to redirect user but port 80 is already allocated to another service working out of docker at same subdomain.

Should I free port 80? Is it the only way? I already tried with error_page 400 but It didn't work for me.

Btw. I dont want to handle HTTP and HTTPS over same port but just redirect all trafic into HTTPS when user uses port 38000, so HTTP won't be used in any case (always redirected) Or I may add another port to handle HTTP redirect but It cannot be port 80 outside of docker. For now I am getting error 400 when trying to use HTTP at that port. It should be redirected or link somehow changed into HTTPS. I am not limited to use 443 inside docker container, it can be also any port.

###DOCKER-COMPOSE

reverseproxy:
image: nginx:1.27.2
container_name: nginx_reverse_proxy
ports:
  - "38000:443"  # React i API
  - "33101:33101"  # phpMyAdmin 

###NGINX

server {
    listen 443;  # (It's docker 38000:443) I want to redirect to HTTPS somehow
    server_name app.aufy.pl;
location / {
    return 301 https://$host$request_uri;  
}

}

#HTTPS server { listen 443 ssl; # (It's also docker 38000:443 but it's SSL and HTTPS link) server_name app.aufy.pl;

ssl_certificate /etc/nginx/certs/cert.crt;  
ssl_certificate_key /etc/nginx/certs/cert.key;  
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'HIGH:!aNULL:!MD5';  

location / {
    proxy_pass http://frontend:3000; 
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_cache_bypass $http_upgrade;
}

}

aufy
  • 13

0 Answers0