Nginx frequently returns 404 PHP FPM

I have a server with Nginx 1.4 in Ubuntu 14.04 and it’s running with PHP5-fpm. The server has multiple domains and sub-domains in a Private cloud server. The server is getting consistent hits from traffic and it’s lot. Everything is fine, but Nginx frequently returns 404, while the case is not in actual and after couple of try it returns the actual output instead of 404. Below is one example of my one of the server block from nginx config.

server {
    listen 80;
    #listen [::]:80;

    root /var/www/appfolder;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name domain-name;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #   proxy_pass;    

    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 /var/www/appfolder;

    # pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #   # With php5-cgi alone:
    #   fastcgi_pass;
    #   # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #location ~ /\.ht {
    #   deny all;

Please help me on this, I have searched a lot, but never got a proper solution. Thanks in advance.

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.


If the problem is with the database connection, then it’s very strange, that the script returns 404-errors. You need to verify that.

  1. What does your PHP-FPM pool look like?
  2. Has this always been a problem or is it something new? If it’s a new problem, what changed?
  3. Do you have any debug logging of the script code?

To scale MySQL for a 1000 connections doesn’t require more than changing the max_connections = 1001, but there a lot of other parameters to look at and it depends on read-write levels: - The wizard is a good, easy tool - The tuner gives you some good hints

@Mohsen47 @hansen Below are some latest http requests: - - [24/Jul/2017:12:41:18 +0000] "POST /index.php?mode=addAction HTTP/1.1" 200 55 "-" "okhttp/3.6.0" - - [24/Jul/2017:12:41:18 +0000] "POST /index.php?mode=addAction HTTP/1.1" 200 56 "-" "okhttp/3.6.0" - - [24/Jul/2017:12:41:18 +0000] "POST /index.php?mode=addAction HTTP/1.1" 200 55 "-" "okhttp/3.6.0" - - [24/Jul/2017:12:41:18 +0000] "POST /index.php?mode=addAction HTTP/1.1" 404 151 "-" "okhttp/3.6.0" - - [24/Jul/2017:12:41:18 +0000] "POST /index.php?mode=addAction HTTP/1.1" 404 151 "-" "okhttp/3.6.0" - - [24/Jul/2017:12:41:18 +0000] "POST /index.php?mode=addAction HTTP/1.1" 200 54 "-" "okhttp/3.6.0" - - [24/Jul/2017:12:41:18 +0000] "POST /index.php?mode=showCoins HTTP/1.1" 404 151 "-" "okhttp/3.2.0" - - [24/Jul/2017:12:41:18 +0000] "POST /index.php?mode=addAction HTTP/1.1" 404 151 "-" "okhttp/3.6.0"

You can see for the same action it’s getting 404 and 200 both but 404 maximum time.