0

I'm currently trying to deploy a Django app on a REHL 7.4 server using Nginx. I've followed these tutorials :

https://simpleisbetterthancomplex.com/tutorial/2017/05/23/how-to-deploy-a-django-application-on-rhel.html

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

The virtualenv and the nginx server seems to be allright. However I'm struggling with two errors:

  • Either I got a 500 error because of worker_connections parameter value (below are logs):

    13494#0: *1021 1024 worker_connections are not enough while connecting to upstream, client: 192.168.1.33, server: 192.168.1.33, request: "GET /Syc/login HTTP/1.0", upstream: "http://192.168.1.33:80/Syc/login", host: "192.168.1.33"

  • Either I increase worker_connections value to > 4096 and I get a 400 error like in this thread 400 Bad Request - request header or cookie too large

Below are my nginx.conf and app.conf, please let me know if there are configuration mistakes and thanks in advance for any help.

nginx.conf:

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}
# set open fd limit to 30000
worker_rlimit_nofile 30000;

http {
    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;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    }
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        large_client_header_buffers 4 32k;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

app.conf

upstream app_server {
    server unix:/opt/sycoma/gunicorn.sock fail_timeout=0;
}

server {
    listen 80;
    server_name 192.168.1.33;  # <- insert here the ip address/domain name
    large_client_header_buffers 4 16k;
    keepalive_timeout 5;
    client_max_body_size 4G;

    access_log /opt/sycoma/logs/nginx-access.log;
    error_log /opt/sycoma/logs/nginx-error.log;

    location /static/ {
        alias /opt/sycoma/venv/Sycoma/Syc/static/;
    }

    location /media/ {
        alias /opt/sycoma/venv/Sycoma/media/;
    }

    location / {
        try_files $uri @proxy_to_app;
    }

    location @proxy_to_app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://192.168.1.33;
    }
}
May.D
  • 1,832
  • 1
  • 18
  • 34

1 Answers1

0

Try to remove/comment the line:

proxy_set_header Host $http_host;

or increase large_client_header_buffers.

kinjelom
  • 6,105
  • 3
  • 35
  • 61
  • The first one (removing proxy_set_header ...) worked for me. But why? What is it about the RHEL that interferes with this? It works fine with that line under CentOS and Ubuntu. – Prasanna Apr 05 '19 at 23:28