Question

502 Bad Gateway, upstream prematurely closed.

There is an error on two pages. How can i fix 502 Bad Gateway? Thanks for help. Have a nice day… http://luxger.com/galeri/motif - 502 error, 178 images http://luxger.com/galeri/gokyuzu - 502 error, 131 images http://luxger.com/galeri/gokyuzu-agac-cicek - no Error, 286 images Nginx Error log:

...upstream prematurely closed connection while reading response header from upstream, client: 84.104.247.91, server: www.luxgergitavan.com, request: "GET /galeri/motif HTTP/1.1",... 

File: /etc/nginx/nginx.conf

worker_processes 4;
pid /run/nginx.pid;

events {
	worker_connections 768;
}
http {

	##
	# Basic Settings
	##
	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;

	server_names_hash_bucket_size 128;

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

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log warn;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-available/*;

}

File: /etc/nginx/sites-available/luxger.com

upstream luxger_app_server {
   server unix:/var/www/luxger.com/run/gunicorn.sock fail_timeout=0;

}

server {
        listen 80;
        #listen [::]:80 default_server ipv6only=on;
        client_max_body_size 4G;
        sendfile on;
        keepalive_timeout 0;
        large_client_header_buffers 8 32k;

        root /var/www/luxger.com/;

        server_name www.luxgergitavan.com luxgergitavan.com luxger.com www.luxger.com;

        access_log /var/www/luxger.com/logs/nginx-access.log;
        error_log /var/www/luxger.com/logs/nginx-error.log;

    keepalive_timeout 0;
    large_client_header_buffers 8 32k;

    location /static/ {
        alias   /var/www/luxger.com/static/;
    }

    location /media/ {
        alias   /var/www/luxger.com/media/;
    }

    location /static/admin {
        alias   /var/www/luxger.com/static/admin/;
    }

        location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
                proxy_buffers 8 32k;
        proxy_buffer_size 64k;
        if (!-f $request_filename) {
            proxy_pass http://luxger_app_server;
            break;
        }


        }
        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #       root /usr/share/nginx/html;
        #}
}
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Sorry to see that your question hasn’t received an answer yet. Unfortunately, after this much time, it is unlikely that an answer for this specific question will be provided. For people still landing here via search, you will want to check the upstream service’s (Gunicorn, php-fpm, NodeJS, etc.) logs and see why it is returning an error.