I have a docker application running on droplet at Digitalocean.
Docker application works smoothly when I stand up.
The api works when I go directly to the IP address.
But when I go to the domain address that I redirect, I get “Bad request 400” error.
The address to which I redirect the subdomain
https://api.mywebsite.com
How can I fix this?
I don’t know where he made a mistake.
Thanks for your help
My nginx.conf file is as follows.
nginx.conf
upstream rest_server{
server django-api:8000;
}
server{
listen 80;
resolver 127.0.0.11;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
proxy_pass http://restgunicorn_server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static/ {
alias /opt/services/hastatakip-django-api/static/;
}
location /media/ {
alias /opt/services/hastatakip-django-api/media/;
}
}
**# SSL**
server {
listen 443 ssl;
resolver 127.0.0.11;
ssl_certificate /usr/share/nginx/certificates/fullchain.pem;
ssl_certificate_key /usr/share/nginx/certificates/privkey.pem;
include /etc/ssl-options/options-nginx-ssl.conf;
ssl_dhparam /etc/ssl-options/ssl-dhparams.pem;
location / {
proxy_pass http://restgunicorn_server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
docker-compose.yml
version: '3'
services:
django-api:
build: .
volumes:
- .:/code
- static_volume:/opt/services/hastatakip-django-api/static
- media_volume:/opt/services/hastatakip-django-api/media
expose:
- "8000"
ports:
- "8000:8000"
networks:
- nginx_network
- djangodb_network
depends_on:
- djangodb
nginx:
build:
context: .
dockerfile: Dockerfile.lets
expose:
- 80
ports:
- "80:80"
- "443:443"
environment:
DOMAIN: api.mywebsite.net
EMAIL: mymail@aaa.com
RENEW_INTERVAL: 12h
volumes:
- ./certificates:/usr/share/nginx/certificates
- ./config/nginx/conf.d:/etc/nginx/conf.d
- static_volume:/opt/services/django-api/static
- media_volume:/opt/services/django-api/media
depends_on:
- django-api
networks:
- nginx_network