ytsejam
ytsejam

Reputation: 3439

django + nginx https redirect shows (414 Request-URI Too Large)

I am trying to solve nginx redirect to https but when I use www.ozkandurakoglu.com I am getting 414 Request-URI Too Large error. Here is my settings for nginx:

upstream ozkan_server {
  server unix:/home/ytsejam/public_html/ozkansimple/run/gunicorn.sock fail_timeout=10s;
}

server {
    listen   80;
    server_name ozkandurakoglu.com www.ozkandurakoglu.com;
    return 301 $scheme:https://ozkandurakoglu.com$request_uri;
}
server {
  listen 443 ssl;
  listen [::]:443 ssl;
  ssl on;
  ssl_certificate /etc/letsencrypt/live/ozkandurakoglu.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/ozkandurakoglu.com/privkey.pem;
  ssl_trusted_certificate /etc/letsencrypt/live/ozkandurakoglu.com/chain.pem;
  ssl_session_timeout 1d;
  ssl_session_cache shared:SSL:50m;
  ssl_session_tickets off;
  ssl_prefer_server_ciphers on;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name www.ozkandurakoglu.com;
  return 301 $scheme:https://ozkandurakoglu.com$request_uri;
}
server {
  listen 443 ssl;
  listen [::]:443 ssl;
  ssl on;
  ssl_certificate /etc/letsencrypt/live/ozkandurakoglu.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/ozkandurakoglu.com/privkey.pem;
  ssl_trusted_certificate /etc/letsencrypt/live/ozkandurakoglu.com/chain.pem;
  ssl_session_timeout 1d;
  ssl_session_cache shared:SSL:50m;
  ssl_session_tickets off;
  ssl_prefer_server_ciphers on;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name  www.ozkandurakoglu.com ozkandurakoglu.com;
  client_max_body_size 4G;
  root /home/ytsejam/public_html/ozkansimple/;
  access_log /home/ytsejam/public_html/ozkansimple/logs/nginx-access.log;
  error_log /home/ytsejam/public_html/ozkansimple/logs/nginx-error.log warn;
  large_client_header_buffers 6 16k;
...
}

can you help me ?

Thanks

Upvotes: 0

Views: 2908

Answers (1)

ytsejam
ytsejam

Reputation: 3439

I answer my question because I had to change both nginx and gunicorn which I did not mention in my question, I had remove $cheme in my server block

server {
    listen   80;
    server_name ozkandurakoglu.com www.ozkandurakoglu.com;
    return 301 https://ozkandurakoglu.com$request_uri;
}

and add

limit_request_line

--limit-request-line INT
4094
The maximum size of HTTP request line in bytes.

to my gunicorn start line.

edit: finally days after correct settings is here

server {
        listen 80;
        server_name ozkandurakoglu.com www.ozkandurakoglu.com;
        return 301 https://www.ozkandurakoglu.com$request_uri;
}
server {
    listen 443 ssl http2;
    server_name  ozkandurakoglu.com;
    return 301 https://www.ozkandurakoglu.com$request_uri;
}
server {
    listen 443 ssl http2;
    server_name  www.ozkandurakoglu.com;

    access_log /var/log/nginx/ozkandurakoglu.com.access.log;
    error_log /var/log/nginx/ozkandurakoglu.com.error.log;

    ssl_certificate         /etc/letsencrypt/live/www.ozkandurakoglu.com/fullchain.pem;
    ssl_certificate_key     /etc/letsencrypt/live/www.ozkandurakoglu.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/www.ozkandurakoglu.com/chain.pem;

    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:64m;
    ssl_session_tickets off;

    ssl_protocols TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-$
    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload";
    ssl_stapling on;
    ssl_stapling_verify on;
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block";
    add_header Referrer-Policy no-referrer-when-downgrade;
    #add_header Content-Security-Policy "default-src https:";

    resolver 8.8.8.8 8.8.4.4;
    resolver_timeout 5s;

  client_max_body_size 4G;

... }

Upvotes: 2

Related Questions