Nginx/FastCGI return 500 Internal Server Error when sending many requests

April 4, 2017 3.1k views
Nginx Ubuntu 16.04

I've deployed Asp.Net Webservice to connect to Riak on Ubuntu 16.04 using latest version of Mono, FastCGI and Nginx. The Webservice works fine when I access it on my browser. It also works fine if I send one request and wait for response before sending another request. The problem occur when I tried to send many requests at the same time (using www class in Unity3D Engine). From my testing I can only send request up to 7 requests simultaneously. More than that and Nginx/FastCGI would return 500 Internal Server Error. Log file has an access log for this error request.

x.x.x.x - - [27/Mar/2017:10:35:20 +0000] "POST /RiakService.asmx/GetValueMapBucket HTTP/1.1" 500 53 "-" "UnityPlayer/5.5.2f1 (http://unity3d.com)" "-"

But there is no error log in /var/log/nginx/error.log relate to this error request. So, it doesn't help at all. My Webservice code shouldn't have any problem because I've tested sending 10 requests on xsp4 instead of Nginx/FastCGI. It works correctly. Every request return correct result and no error. Is there any configuration in Nginx/FastCGI relate to this behavior? This is my Nginx configuration for proxy server.

server {
location ~.asmx(.) {
fastcgisplitpath_info ^(.+.asmx)(.
)$;
fastcgiparam SCRIPTFILENAME $documentroot$fastcgiscriptname;
fastcgi
param PATHINFO $fastcgipathinfo;
include /usr/local/nginx/conf/fastcgi
params;
fastcgi_pass 127.0.0.1:9000;
}
}

I tried using debug mode. These are log files when I sent 10 requests. All requests returned 500 Internal Server Error. I'm still a novice in this field. I really appreciate any help.
https://pastebin.com/CJMH1GyB

2 comments
  • The above configuration is old and some characters were removed when I posted. This is my current configuration file.

    server {
       error_log /var/log/nginx/riakclient.log debug;
    
       location ~\.asmx(.*) {
         fastcgi_split_path_info ^(.+\.asmx)(.*)$;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         fastcgi_param PATH_INFO $fastcgi_path_info;
         include /etc/nginx/fastcgi_params;
         #fastcgi_index Default.asmx;
         fastcgi_pass 127.0.0.1:9000;
      }
    }
    
1 Answer

@nattawitta

From looking at the Mono Docs for NGINX, they recommend a slightly different configuration.

 server {
         listen   80;
         server_name  www.domain1.xyz;
         access_log   /var/log/nginx/your.domain1.xyz.access.log;
         root /var/www/www.domain1.xyz/;

         location / {
                 index index.html index.htm default.aspx Default.aspx;
                 fastcgi_index Default.aspx;
                 fastcgi_pass 127.0.0.1:9000;
                 include /etc/nginx/fastcgi_params;
         }
 }

With:

fastcgi_param  PATH_INFO          "";
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

.. being added to fastcgi_params, or replacing what is already there if those are already set to values other than the above.

The default location of fastcgi_params on Ubuntu is normally /etc/nginx/fastcgi_params unless you have modified it and placed it elsewhere or installed a version of NGINX that isn't in their repos.

http://www.mono-project.com/docs/web/fastcgi/nginx/

...

You can further modify the above server block and add error_log to create a log specifically for that block as well. You'd add:

error_log /var/log/nginx/your.domain1.xyz.error.log;

.. below or above access_log. Once changes are made, you'd want to reload or restart NGINX.

service nginx reload
service nginx restart

or

systemctl reload nginx
systemctl restart nginx
  • I just noticed that it was my old configuration and some characters were removed when I posted it. This is my current configuration.

    server {
       error_log /var/log/nginx/riakclient.log debug;
    
       location ~\.asmx(.*) {
         fastcgi_split_path_info ^(.+\.asmx)(.*)$;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         fastcgi_param PATH_INFO $fastcgi_path_info;
         include /etc/nginx/fastcgi_params;
         #fastcgi_index Default.asmx;
         fastcgi_pass 127.0.0.1:9000;
      }
    }
    

    It's not the same as in official page because for some reasons the configuration in official pages didn't work for me. I searched and used this guide instead.
    https://www.geekytidbits.com/nginx-with-asp-net-page-methods/

    This configuration works for me. But it doesn't work if I send many requests at the same time.

    • @nattawitta

      As a general rule, you want to setup a complete server block.

      With the server block you have right now, there's no specific routing to your domain and it will accept any request on any domain that is pointing to your Droplet's IP.

      Above the error_log directive, you'd want to add:

          listen 80;
          server_name domain.com www.domain.com;
      
          root /path/to/home;
      

      ... and swap out domain.com with your domain, and /path/to/home with the location of the files you're serving.

      That being said, when removing debug from error_log, something should be getting sent to either:

      /var/log/nginx/riakclient.log
      

      or

      /var/log/nginx/error.log
      

      The only time you shouldn't see something being logged to the above error.log is if you're using a modified NGINX configuration (check /ect/nginx/nginx.conf) and see the error log to a different location.

      As far as NGINX goes, all NGINX is doing here is passing the request for files over to your handler for processing. The issue could range from the application is taking too long to load, to you have too few resources to handle the number of requests (i.e. CPU/RAM), to any other number of issues.

      For example, when an error, such as the one you're receiving, applies to fastcgi using PHP, the issue is normally with the PHP application/script or PHP-FPM. NGINX is just passing the request over and expecting a response so that it can serve the request based on what it receives.

      The first thing I'd recommend doing is making sure logging is also setup for your app so that when you receive a request, something is logged. You'd then take a look at the application logs as well as that of the server to see if there's more to the error.

Have another answer? Share your knowledge.