I can't stop getting 400 bad request. After some research, I found out that this meant that the request had bad headers due to a bad configuration
Here is my nginx.conf
file:
user nginx;
worker_processes auto;
events {
worker_connections 1000;
}
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
set_real_ip_from 192.168.0.0/16;
set_real_ip_from 172.16.0.0/12;
set_real_ip_from 10.0.0.0/8;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
log_format main '$remote_addr - $remote_user "$request" '
'$status $body_bytes_sent $http_host "$http_referer" '
'"$http_user_agent"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
}
Here is the output to logs when I do a get request to the server:
" while reading PROXY protocol, client: 172.26.0.5, server: 0.0.0.0:80
2021/09/16 11:08:07 [error] 8#8: *8 broken header: "GET /favicon.ico HTTP/1.1
pragma: no-cache
cache-control: no-cache
sec-ch-ua: "Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"
sec-ch-ua-mobile: ?0
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
sec-ch-ua-platform: "Windows"
accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8
sec-fetch-site: same-origin
sec-fetch-mode: no-cors
sec-fetch-dest: image
referer: https://localhost/
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
host: localhost
X-Forwarded-For: 172.26.0.1
This nginx reverse proxy is running on a docker container with the following dockerfile
:
FROM nginx:1.16
ENV DOCKER_IMAGE nginx
ENV DOCKER_NAME nginx
ENV TZ Africa/Tunis
RUN set -x && \
# tiny helper to reload nginx config
printf '#!/bin/bash\n/usr/sbin/nginx -s reload\n' >> /usr/local/bin/nginx-reload && \
chmod +x /usr/local/bin/nginx-reload && \
# delete nginx default server config
rm /etc/nginx/conf.d/default.conf
COPY ./conf/ /etc/
ENV WORKER_PROCESSES auto
ENV WORKER_CONNECTIONS 1024
ENV SERVER_NAME localhost