Discover Centmin Mod today
Register Now

Nginx Nginx 404 not found on index page

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by pamamolf, Feb 25, 2016.

  1. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Hi
    When i visit the domain is not loading my index.php and on logs i have only this:

    Code:
    error] 1496#1496: *10 open() "/home/nginx/domains/sub.domain.com/public/maintenance.html" failed (2: No such file or directory) while sending to client
    And don't know why is looking there:

    Code:
    maintenance.html
    After refreshing the page i am getting 502 bad gateway :(

    Code:
    [error] 3235#3235: *40 no live upstreams while connecting to upstream, client: 79.130.47.68, server: sub.domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://phpbackend", host: "sub.domain.com"
    
    :(
     
    Last edited: Feb 25, 2016
  2. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    1:48 AM
    Nginx 1.13.x
    MariaDB 5.5
    which version of centmin mod ? fresh install ? upgraded install ?

    using multiple php-fpm pools ? does it happen if you turn multiple php-fpm pool feature off and use default single php-fpm pool ?

    123.09beta01 sitestatus enabled Beta Branch - sitestatus maintenance mode | Centmin Mod Community ? Looks like you enabled site maintenance mode via sitestatus off, but don't have the maintenance.html file in your site's web root so gives 404 error. Does sitestatus on command fix it ?

    When you create a new nginx vhost domain via centmin.sh menu option 2 or /usr/bin/nv cli command line, you will create the Nginx vhost files and directories. You will get an outputted the path location where it will create the domain name's vhost conf file named newdomain.com.conf (and newdomain.com.ssl.conf if you selected yes to self signed SSL)
    • Nginx vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.conf
    • Nginx HTTP/2 SSL vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf
    • Nginx Self-Signed SSL Certificate Directory at /usr/local/nginx/conf/ssl/newdomain.com
    • Vhost public web root will be at /home/nginx/domains/newdomain.com/public
    • Vhost log directory will be at /home/nginx/domains/newdomain.com/log
    Please post the contents of /usr/local/nginx/conf/conf.d/newdomain.com.conf and if applicable /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf wrapped in CODE tags (outlined at How to use forum BBCODE code tags | Centmin Mod Community
     
  3. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    1:48 AM
    Nginx 1.13.x
    MariaDB 5.5
    Looks like you enabled site maintenance mode via sitestatus off, but don't have the maintenance.html file in your site's web root so gives 404 error. Does sitestatus on command fix it ?
     
  4. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    When i click on my subdomain i am getting once 404 and once 502 bad gateway :(

    which version of centmin mod ? fresh install ? upgraded install ?

    Latest 09 beta1 installed yesterday.

    using multiple php-fpm pools ?

    yes

    /usr/local/nginx/conf/nginx.conf

    Code:
    user              nginx nginx;
    worker_processes 8;
    worker_priority -10;
    
    worker_rlimit_nofile 260000;
    timer_resolution 100ms;
    
    pcre_jit on;
    include /usr/local/nginx/conf/dynamic-modules.conf;
    
    
    pid         logs/nginx.pid;
    
    events {
        worker_connections  4096;
        accept_mutex off;
        accept_mutex_delay 200ms;
        use epoll;
        #multi_accept on;
    }
    
    http {
    upstream phpbackend {
    ip_hash;
    keepalive 5;
      server 127.0.0.1:9000 weight=50;
      server 127.0.0.1:9002 weight=50;
      server 127.0.0.1:9003 weight=50;
      server 127.0.0.1:9004 weight=50;
      server 127.0.0.1:9005 weight=50;
    }
    aio threads;
    map_hash_bucket_size 512;
    map_hash_max_size 4096;
    server_names_hash_bucket_size 128;
    server_names_hash_max_size 2048;
    
    limit_req_zone $binary_remote_addr zone=xwplogin:16m rate=40r/m;
    #limit_conn_zone $binary_remote_addr zone=xwpconlimit:16m;
    
    more_set_headers "Server: nginx secure";
    more_set_headers "X-Powered-By: secure";
    
    # uncomment cloudflare.conf include if using cloudflare for
    # server and/or vhost site
    #include /usr/local/nginx/conf/cloudflare.conf;
    include /usr/local/nginx/conf/maintenance.conf;
    include /usr/local/nginx/conf/vts_http.conf;
    include /usr/local/nginx/conf/geoip.conf;
    #include /usr/local/nginx/conf/pagespeedadmin.conf;
    include /usr/local/nginx/conf/fastcgi_param_https_map.conf;
    
    log_format      main    '$remote_addr - $remote_user [$time_local] $request '
                    '"$status" $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"'
                    ' "$connection" "$connection_requests" "$request_time"';
    
    access_log  logs/access.log combined buffer=128k flush=5m;
    error_log   logs/error.log warn;
    
        index  index.php index.html index.htm;
        include       mime.types;
        default_type  application/octet-stream;
        charset utf-8;
    
            sendfile on;
            sendfile_max_chunk 512k;
            tcp_nopush  on;
            tcp_nodelay on;
            server_tokens off;
            server_name_in_redirect off;
          
            keepalive_timeout  8;
            keepalive_requests 1000;
            lingering_time 20s;
            lingering_timeout 5s;
            keepalive_disable msie6;
    
        gzip on;
        gzip_vary   on;
        gzip_disable "MSIE [1-6]\.";
            gzip_static on;
            gzip_min_length   1400;
            gzip_buffers      32 8k;
            gzip_http_version 1.0;
            gzip_comp_level 5;
            gzip_proxied    any;
            gzip_types text/plain text/css text/xml application/javascript application/x-javascript application/xml application/xml+rss application/ecmascript application/json image/svg+xml;
    
    client_body_buffer_size 256k;
    client_body_in_file_only off;
    client_body_timeout 10s;
    client_header_buffer_size 64k;
    ## how long a connection has to complete sending
    ## it's headers for request to be processed
    client_header_timeout  8s;
    client_max_body_size 50m;
    connection_pool_size  512;
    directio  4m;
    ignore_invalid_headers on;     
    large_client_header_buffers 8 64k;
    output_buffers   8 256k;
    postpone_output  1460;
    proxy_temp_path  /tmp/nginx_proxy/;
    request_pool_size  32k;
    reset_timedout_connection on;
    send_timeout     15s;
    types_hash_max_size 2048;
    
    # for nginx proxy backends to prevent redirects to backend port
    # port_in_redirect off;
    
    open_file_cache max=50000 inactive=60s;
    open_file_cache_valid 120s;
    open_file_cache_min_uses 2;
    open_file_cache_errors off;
    open_log_file_cache max=10000 inactive=30s min_uses=2;
    
    ## limit number of concurrency connections per ip to 16
    ## add to your server {} section the next line
    ## limit_conn limit_per_ip 16;
    ## uncomment below line allows 500K sessions
    # limit_conn_log_level error;
    #######################################
    # use limit_zone for Nginx <v1.1.7 and lower
    # limit_zone $binary_remote_addr zone=limit_per_ip:16m;
    #######################################
    # use limit_conn_zone for Nginx >v1.1.8 and higher
    # limit_conn_zone $binary_remote_addr zone=limit_per_ip:16m;
    #######################################
    
    include /usr/local/nginx/conf/conf.d/*.conf;
    }
    /usr/local/nginx/conf/php.conf

    Code:
    location ~ \.php$ {
      include /usr/local/nginx/conf/503include-only.conf;
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_next_upstream error timeout http_500 http_503;
        fastcgi_pass phpbackend;
        fastcgi_keep_conn on;
        #fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    $request_filename;
        #fastcgi_param PHP_ADMIN_VALUE open_basedir=$document_root/:/usr/local/lib/php/:/tmp/;
    
    # might shave 200+ ms off PHP requests
    # which don't pass on a content length header
    # slightly faster page response time at the
    # expense of throughput / scalability
    #sendfile on;
    #tcp_nopush off;
    #keepalive_requests 0;
    
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 512k;
    fastcgi_buffers 512 16k;
    fastcgi_busy_buffers_size 1m;
    fastcgi_temp_file_write_size 4m;
    fastcgi_max_temp_file_size 4m;
    fastcgi_intercept_errors on;
    
    # next 3 lines when uncommented / enabled
    # allow Nginx to handle uploads which then
    # passes back the completed upload to PHP
    #fastcgi_pass_request_body off;
    #client_body_in_file_only clean;
    #fastcgi_param  REQUEST_BODY_FILE  $request_body_file;
    
    #new .04+ map method
    fastcgi_param HTTPS $server_https;
    
    # comment out PATH_TRANSLATED line if /usr/local/lib/php.ini sets following:
    # cgi.fix_pathinfo=0
    # as of centminmod v1.2.3-eva2000.01 default is set to cgi.fix_pathinfo=1
    
    fastcgi_param  PATH_INFO          $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
    
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  REQUEST_SCHEME     $scheme;
    fastcgi_param  HTTPS              $https if_not_empty;
    
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
    
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    
    # Set php-fpm geoip variables
    fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
    fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
    fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
    fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
    fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
    fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
    fastcgi_param GEOIP_REGION $geoip_region;
    fastcgi_param GEOIP_CITY $geoip_city;
    fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;
    fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
    fastcgi_param GEOIP_LATITUDE $geoip_latitude;
    fastcgi_param GEOIP_LONGITUDE $geoip_longitude;
    
    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;
    
                       }
    Code:
    # Centmin Mod Getting Started Guide
    # must read [URL='http://centminmod.com/getstarted.html']Getting Started Guide - CentminMod.com LEMP Nginx web stack for CentOS[/URL]
    
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    #server {
    #  listen  80;
    #  server_name sub.domain.com;
    #  return 301 $scheme://[URL='http://www.sub.domain.com$request_uri;']www.sub.domain.com$request_uri;[/URL]
    #  }
    
    server {
    
      server_name sub.domain.com [URL='http://www.sub.domain.com;']www.sub.domain.com;[/URL]
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      #add_header X-Content-Type-Options "nosniff" always;
      #add_header X-Xss-Protection "1; mode=block" always;
      #add_header X-Content-Type-Options "nosniff" always; 
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/sub.domain.com/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/sub.domain.com/log/error.log;
    
      root /home/nginx/domains/teammx.bariatricpal.com/public;
      # uncomment cloudflare.conf include if using cloudflare for
      # server and/or vhost site
      #include /usr/local/nginx/conf/cloudflare.conf;
      include /usr/local/nginx/conf/503include-main.conf;
    
      # prevent access to ./directories and files
      location ~ (?:^|/)\. {
      deny all;
      } 
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    # block common exploits, sql injections etc
    #include /usr/local/nginx/conf/block.conf;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      # Enable for vBulletin usage WITHOUT vbSEO installed
      # More example Nginx vhost configurations at
      # [URL='http://centminmod.com/nginx_configure.html']Nginx Configuration Examples - CentminMod.com LEMP Nginx web stack for CentOS[/URL]
      try_files     $uri $uri/ /index.php;
    
      }
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    
     
  5. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    1:48 AM
    Nginx 1.13.x
    MariaDB 5.5
    once only all always 502 now ? means your php-fpm pools are down or not running.. check to see and restart php-fpm service

    503 error maintenance probably triggered as site is unavailable due to php-fpm being down as the include file in server context for
    Code:
    include /usr/local/nginx/conf/503include-main.conf;
    has
    Code:
         error_page 503 @maintenance;
         location @maintenance {
              #if ($maintenance = 1) {
              rewrite ^ /maintenance.html break;
              #ry_files /maintenance.html =503;
              #}
         }
    so it caught that php-fpm was down and thus site was 503 unavilable and attempted to rewrite to your maintenance.html which doesn't exist
     
  6. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Never enable this mode and sitestatus on didn't fix it :(
    On centmin.sh also i have :


    Code:
    NGINX_UPDATEMAINTENANCE='n'
    PHP_UPDATEMAINTENANCE='n'
    MARIADB_UPDATEMAINTENANCE='n'
     
  7. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    first time when i visit 404 then 502 and then 404 and then 502 a rotation :(

    Is there any easy fast way to disable the pools and check again? Or i must revert all settings one by one?
     
  8. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    1:48 AM
    Nginx 1.13.x
    MariaDB 5.5
    in /usr/local/nginx/conf/php.conf include change
    Code:
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_pass phpbackend;
    back to using single php-fpm pool
    Code:
       fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass phpbackend;
    and restart php-fpm
     
  9. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Didn't work :(

    I upload the phpinfo file there and try to visit my domain and it is working without any issues......

    Permissions are set to nginx:nginx but other files not loading :(
     
  10. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    [​IMG]
     
  11. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    phpmyadmin is givving me 500 internal server error also :(
     
  12. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    1:48 AM
    Nginx 1.13.x
    MariaDB 5.5
    indeed your php-fpm pools logged 404 and 502 errors according to 4xx and 5xx columns

    try disabling the multiple php-fpm pools entirely by commenting out with semi-colon in /usr/local/etc/php-fpm.conf
    Code:
    include=/usr/local/nginx/conf/phpfpmd/*.conf
    to
    Code:
    ;include=/usr/local/nginx/conf/phpfpmd/*.conf
    ensure you had php.conf include switched back to single pool as per Nginx - Nginx 404 not found on index page | Centmin Mod Community

    and then restart php-fpm pools
     
  13. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Now i am getting only
    502 Bad Gateway

    Code:
    [root@server centminmod-123.09beta01]# ss -nlt | grep 900
    LISTEN     0      8150   127.0.0.1:9000                     *:*

    Code:
    [root@server centminmod-123.09beta01]# php -v
    
    PHP 5.6.18 (cli) (built: Feb 24 2016 17:01:29)
    
    Copyright (c) 1997-2016 The PHP Group
    
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    
        with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies


    I just recompile nginx and php in case that something was wrong but nothing :(
     
  14. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    I don't get it :(

    How is possible for php info file to run without any issues and not other php files or phpmyadmin files are able to load ? :(
     
  15. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    1:48 AM
    Nginx 1.13.x
    MariaDB 5.5
    To troubleshoot Nginx and PHP-FPM issues you'd want to check the domain site's vhost access.log and error.log logs located within directory at /home/nginx/domains/yourdomain.com/logs. You can see a full overview at centminmod.com/configfiles.html

    FAQ item 19 has more info on all Centmin Mod relevant log files locations and how to use tail command to view a sample of the entries.

    Also post the contents of your site's nginx vhost http /usr/local/nginx/conf/conf.d/yourdomain.com.conf and/or /usr/local/nginx/conf/conf.d/yourdomain.com.ssl.conf in BBCODE CODE tags as outlined at How to use forum BBCODE code tags | Centmin Mod Community
     
  16. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Fixed by removing the maintenance include.

    How can i disable it forever as i don't want it at all on future installs as this didn't work:

    Code:
    NGINX_UPDATEMAINTENANCE='n'
    PHP_UPDATEMAINTENANCE='n'
    MARIADB_UPDATEMAINTENANCE='n'
    I don't want to trigger it in any way!
     
  17. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    1:48 AM
    Nginx 1.13.x
    MariaDB 5.5
    removing maintenance include is enough, which one was it /usr/local/nginx/conf/503include-main.conf ?

    I am using this on this very forum and centminmod.com site right now without problems so strange
     
  18. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Code:
    /usr/local/nginx/conf/conf.d/sub.domain.com.conf
    and i add the comment here:

    Code:
    #include /usr/local/nginx/conf/503include-main.conf;
    Don't know why it trigger .......

    And i think it has a typo also there:

    Code:
        # only uncomment if you do not need to exclude images or js
        # from 503 redirect rewrites
         #include /usr/local/nginx/conf/503include-only.conf;
         error_page 503 @maintenance;
         location @maintenance {
              #if ($maintenance = 1) {
              rewrite ^ /maintenance.html break;
              #ry_files /maintenance.html =503;
              #}
         }
    should be:
    Code:
    #try_files /maintenance.html =503;
    ?
     
    • Informative Informative x 1
  19. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    1:48 AM
    Nginx 1.13.x
    MariaDB 5.5
    yeah typo but commented out so doesn't matter heh
     
  20. pamamolf

    pamamolf Well-Known Member

    2,825
    253
    83
    May 31, 2014
    Ratings:
    +449
    Local Time:
    5:48 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Should i keep this commented?

    Code:
    fastcgi_param PHP_ADMIN_VALUE open_basedir=$document_root/:/usr/local/lib/php/:/tmp/;
    at:

    Code:
     /usr/local/nginx/conf/php.conf