1

I can't put an http block/directive on nginx config file, I'm trying to increase timeout of file upload via curl ,It says http" directive is not allowed here in /etc/nginx/conf.d/default.conf:1

I'm using django and I can't seems to work it out.

http {
    fastcgi_read_timeout 300;
    proxy_read_timeout 300;

    server {
        listen       80;
        server_name  localhost;

        location /media/ {
            try_files $uri /dev/null =404;
        }

        location / {
            proxy_redirect     off;
            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_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   X-Forwarded-Host $server_name;
            proxy_pass         http://app:8000;
            client_max_body_size 100M;
            proxy_temp_file_write_size 64k;
            proxy_connect_timeout 10080s;
            proxy_send_timeout 10080;
            proxy_read_timeout 10080;
            proxy_buffer_size 64k;
            proxy_buffers 16 32k;
            proxy_busy_buffers_size 64k;
            proxy_redirect off;
            proxy_request_buffering off;
            proxy_buffering off;
        }
    }
}

1 Answers1

1

The http directive is already used in /etc/nginx/nginx.conf. Open it, you'll find include /etc/nginx/conf.d/*.conf; at the end of the file.

Solution: delete http directive from /etc/nginx/conf.d/default.conf. You can change the *_read_timeout parameters whether inside or outside of the server directive.

Philip Tzou
  • 5,926
  • 2
  • 18
  • 27
  • I can't find this file on my directory /etc/nginx/nginx.conf, Also I'm using a docker so all dependencies are under my current project folder and nothing else. I also did tried changing read_timeout on server block but nothing happened, that's why I'm adding a protocol level timeout but I can't make it to work. – bonvivant sentoy May 09 '19 at 03:46
  • @bonvivantsentoy You also have a "`proxy_read_timeout`" under the `location / {}`. Did you mean to change it to 300s? – Philip Tzou May 09 '19 at 03:54
  • I can't find the file nginx.conf, but removing http block, and then putting the proxy timeout above server block solves the problem, it seems there is a default nginx conf that I can't seems to locate. – bonvivant sentoy May 13 '19 at 01:22
  • @bonvivantsentoy Since you are using Docker, you can only locate the file in the Docker container but not your host system. Follow this answer to access the container: https://stackoverflow.com/a/30173220/2644759 – Philip Tzou May 15 '19 at 19:03