Score:0

nginx is getting GET / request although its wrong

us flag

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.

djdomi avatar
za flag
hi, it matters what you want to use. that means that you should use the 404 first and then the admin directive imho
scaryhamid avatar
us flag
@djdomi hello, thanks for answering but it did not work im still getting the same log from nginx access.log, i already used this config on another server and i only have this problem here
djdomi avatar
za flag
what happened while you disable the last part, and does not work is not an error description ;) if you change the configuration or environment, you need to reflect the changes also on the question, please show the output of `nginx -T`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.