So I run a nginx container with docker-compose:
services:
  nginx:
    build:
      context: .
      dockerfile: Dockerfile
    restart: always
    container_name: webserver_nginx
    hostname: nginx
    stop_grace_period: 1m30s
    healthcheck:
      test: ["CMD-SHELL", "curl -sf http://127.0.0.1/ -o /dev/null || exit 1"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    ports:
      - 443:443
      - 80:80
    volumes:
      # Service Restriction with password
      - ./.credentials/.htpasswd:/var/.credentials/.htpasswd
      # Nginx Configurations
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./proxy_params:/etc/nginx/proxy_params
      - ./conf:/etc/nginx/conf.d
      #Nginx serve static files
      - /var/backups/off:/var/web_data/off
      # Nginx Logging
      - /var/log/nginx:/var/log/nginx
    networks:
      - webserver_network
networks:
  webserver_network:
    external: true
Dockerfile:
FROM nginx
CMD ["nginx", "-g", "daemon off;"]
my nginx.conf:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
    worker_connections 1024;
}
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/nginx/access.log main;
    sendfile on;
    keepalive_timeout 65;
    include /etc/nginx/conf.d/*.conf;
}
and config for my container:
server {
  listen 80;
  listen [::]:80;
  server_name name.com;
  location /admin {
    proxy_pass http://off:4000;
    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_read_timeout 100;
    proxy_http_version 1.1;
  }
  location /static {
    alias /var/web_data/off/collectstatic;
  }
  location /media {
    alias /var/web_data/off/upload;
  }
  location / {
    return 404;
  }
}
so whenever i try to request http://name.com/admin i get this kind of log from access.log:
127.0.0.1 - - [16/May/2022:15:53:42 +0000] "GET / HTTP/1.1" 404 153 "-" "curl/7.74.0" "-"
127.0.0.1 - - [16/May/2022:15:55:12 +0000] "GET / HTTP/1.1" 404 153 "-" "curl/7.74.0" "-"
127.0.0.1 - - [16/May/2022:15:56:42 +0000] "GET / HTTP/1.1" 404 153 "-" "curl/7.74.0" "-"
and i get 502 Gateway error from nginx on the browser
even when i try to access main site like http://name.com/ i keep getting 502 Error
my container compose is like:
version: '3.8'
services:
  offch:
    build:
      context: .
      dockerfile: deploy/beta/Dockerfile
      args:
        WORKING_DIR: /app
    container_name: off
    hostname: django
    restart: 'always'
    command: gunicorn -c deploy/beta/configs/gunicorn/conf.py --chdir api api.wsgi:application
    volumes:
      # Source Code of project
      - .:/app
      # Collect Static files
      - /var/backups/offch/collectstatic:/collectstatic
      # Media Files (Uploads)
      - /var/backups/offch/upload:/app/media/upload
      - /var/log/upstart:/var/log/upstart
    stop_grace_period: 1m30s
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:4000"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    ports:
      - "4000:4000"
    networks:
      - webserver_network
networks:
  webserver_network:
    external: true
Btw i can access the site through ip and port i only have this problem with nginx.