简体   繁体   中英

Nginx 1.4.6 throwing 503 errors

Nginx 1.4.6 throwing 503 errors

I have configured 2 websites (wordpress and laravel v4) on digitalocean droplet - nginx/1.4.6 (Ubuntu).

Both of the websites normally works very good and quick.

But at the time of any data save in laravel website, it throws 503 error. and in wordpress it does not thorough 503 error, but takes too long time to response near about 1-3min at the time of saving any post or any data.

Both sites virtual host configuration is same as below.

server {
        listen 80;

        listen 443 ssl;

        root /var/www/domain1.com/public_html;

        index index.php index.html index.htm;

        ssl_certificate /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;

        # Make site accessible from http://localhost/
        server_name domain1.com www.domain1.com;


        access_log off;

        #GZIP Configuration
        gzip on;
        gzip_min_length 100;
        gzip_comp_level 3;

        gzip_types text/plain;
        gzip_types text/css;
        gzip_types text/javascript;

        gzip_disable "msie6";



        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
                if ($host !~* ^www\.)
                {
                        rewrite  ^/(.*)$  http://www.$host/$1  permanent;
                }
                proxy_read_timeout 300;
        }


        error_page 404 /error.html;


        location ^~ /error.html {
                rewrite ^/.* http://www.domain1.com permanent;
        }


        location ~* \.(css|js|jpg|png|gif)$ {
                access_log off;
                expires 1M;
                add_header Pragma public;
                add_header Cache-Control public;
                add_header Vary Accept-Encoding;
        }


        try_files $uri $uri/ @rewrite;

        location @rewrite {
               rewrite ^/(.*)$ /index.php?_url=/$1;
        }


        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_read_timeout 600s;
                #fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;

                fastcgi_param PATH_INFO    $fastcgi_path_info;


                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

}

I have also checked error logs and there's nothing critical has been found.

Please guide me, why Laravel v4 website is showing 503 errors, and why wordpress site is slow at the time of saving data.

The 503 means that the service is unresponsive. I guess you are getting timeouts due to laraval using too much of your resources ie memory, possibly maxing out on your droplet.

From your config I can seen that you had a php-fpm socket but decided to use the php via port 9000.

#fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_pass 127.0.0.1:9000;

I would recommend configuring php-fpm with 2 different pools, one for wordpress and another for laravel and then have them setup to listen to different sockets with different setting per pool ie wordpress can have php_value[memory_limit] = 128M and laravel php_value[memory_limit] = 64M . Although this is just an idea, as there is plenty of setting you can have per pool.

Additionally your config has got very generous timeouts setup:

proxy_read_timeout 300

fastcgi_read_timeout 600s

It's very unusual to wait 5 or 10 minutes for response.

The best way in my opinion will be to:

  • Go with php-fpm and different socket -> custom settings per site
  • Install the NewRelic it's free for the basic level, this will let you see what is going on with your server. ie memory usage, how long it takes to execute a request etc. Hopefully it will help you find an issue with your code ie why it takes so long for you laravel to save data.
  • Change the timeouts ie lower it down 5 and 10 minutes is crazy.
  • Possibly upgrade your droplet, depending on your findings.
  • This is good website with instructions on how to tweak php-fpm and nginx.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM