nginx server can no longer find the index.php file after working for a few days

0

My website in AWS Elastic Beanstalk using php 8.1 and nginx is running OK after deployment for a few days. However a few days later the website is down due to nginx error that says it cannot find index.php. Error log of nginx showed nginx was accessing the wrong root directory '/usr/share/nginx/html' even it seemed to work fine in the beginning. If I define ' root /var/www/html;' in nginx.conf , nginx will not restart and show error "root directive is duplicate".

The error message show the index.php cannot be found is :

The page you are looking for is not found. 
 Something has triggered missing webpage on your website. This is the default 404 error page for nginx that is distributed with Amazon Linux 2. It is located /user/share/nginx/html/404.html 
 You should customize this error page for your own site or edit the error_page directive in the nginx configuration file /etc/nginx/nginx.conf

I have to re-deploy the package in AWS Elastic Beanstalk to make the website running again. But a few days (7 days) later the same error occurs again. What is the issue and how to fix it ?

I check the error log of nginx and it shows :

         ---- lots of error message -----
 2024/03/05 10:04:05 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:05 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:05 [error] 2641#2641: *264 open() "/usr/share/nginx/html/_wel-known/pki-validation/883d551d-7523-4JUdGzvrMFDWrUUwY3toJATSeNwjn54LkCnKBPRzDuhzi5vSepHfUickJN$
2024/03/05 10:04:05 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:06 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:06 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:06 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:06 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:07 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:07 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:07 [error] 2641#2641: *264 "/usr/share/nginx/html/wp-content/plugins/backup-backup/includes/index.php" is not found (2: No such file or directory), client$
2024/03/05 10:04:07 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:08 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:08 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:08 [error] 2641#2641: *264 open() "/usr/share/nginx/html/alfanew.php7" failed (2: No such file or directory), client: 172.31.3.144, server: _, request: "G$
2024/03/05 10:04:09 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:09 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:09 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:09 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:10 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:10 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:10 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:10 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:10 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:11 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 
  ----- a lots of same errors as above line ----
2024/03/05 10:04:15 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:15 [error] 2641#2641: *264 open() "/usr/share/nginx/html/4JUdGzvrMFDWrUUwY3toJATSeNwjn54LkCnKBPRzDuhzi5vSepHfUickJNxRL2gjkNrSqtCoRUrEDAgRwsQvVCjZbRyFTLRNyD$
2024/03/05 10:04:16 [error] 2641#2641: *264 open() "/usr/share/nginx/html/alfanew.php7" failed (2: No such file or directory), client: 172.31.3.144, server: _, request: "G$
2024/03/05 10:04:16 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:16 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:16 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:17 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:17 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:17 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:17 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:17 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:18 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:18 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:18 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:18 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:04:19 [error] 2641#2641: *264 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.3.144, server: _, $
2024/03/05 10:06:43 [error] 2640#2640: *358 open() "/usr/share/nginx/html/Core/Skin/Login.aspx" failed (2: No such file or directory), client: 172.31.43.174, server: _, re$
2024/03/05 10:11:42 [error] 2641#2641: *399 open() "/usr/share/nginx/html/Core/Skin/Login.aspx" failed (2: No such file or directory), client: 172.31.3.144, server: _, req$
2024/03/05 10:13:37 [error] 2640#2640: *416 open() "/usr/share/nginx/html/images-s3/images/us/favicon.ico" failed (2: No such file or directory), client: 172.31.43.174, se$
2024/03/05 10:13:39 [error] 2640#2640: *416 open() "/usr/share/nginx/html/robots.txt" failed (2: No such file or directory), client: 172.31.43.174, server: _, request: "GE$
2024/03/05 10:13:39 [error] 2640#2640: *417 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.31.43.174, server: _, request: "G$
              ----- lots of error message here -----

I store my nginx.conf in .platform/nginx/nginx.conf. The nginx.conf is as following:

#Elastic Beanstalk Nginx Configuration File
user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    31486;

events {
    worker_connections  1024;
}

http {
    server_tokens off;
    
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    include       conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
        default     "upgrade";
    }

    server {

        location ^~ /pv/ {
           #  allow 192.168.1.1/24;
           deny all;
           return 404;
        }
     
        listen        80 default_server;
        access_log    /var/log/nginx/access.log main;

        client_header_timeout 60;
        client_body_timeout   60;
        client_max_body_size  50M;
        keepalive_timeout     60;
        gzip                  off;
        gzip_comp_level       4;
        gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;

    server_name mywebsitename.com;
    ## root /var/www/html;     ## this line produce duplicate root error in AWS EBS
    index index.php;
    error_page 404 /index.php;

    location /app/upload_video.php {
         client_max_body_size 2084M;
    }
    
    if ($http_user_agent ~ "Snabcd"){
        rewrite ^/?cup/product/([^/]+)/([^/]+)/([^/]+)/location/([^/]+)/([^/]+)/([^/]+)(?:/(menu-selected)/([^/]+)|)/?$ https://$host/indexapp.php?c1=$1&c2=$2&c3=$3&r2=$4&r3=$5&r4=$6&f_urlseo=1&f_idxt=cpn&$7=$8 last;
        rewrite ^/?cup/product/([^/]+)/([^/]+)/([^/]+)(?:/(menu-selected)/([^/]+)|)/?$ https://$host/indexapp.php?c1=$1&c2=$2&c3=$3&f_urlseo=1&f_idxt=cpn&$4=$5 permanent ;
    }

    if ($http_user_agent !~ "Snabcd"){
        rewrite ^/?cup/product/([^/]+)/([^/]+)/([^/]+)/location/([^/]+)/([^/]+)/([^/]+)(?:/(menu-selected)/([^/]+)|)/?$ https://$host/indexpc.php?c1=$1&c2=$2&c3=$3&r2=$4&r3=$5&r4=$6&f_urlseo=1&f_idxt=cpn&$7=$8 last;
        rewrite ^/?cup/product/([^/]+)/([^/]+)/([^/]+)(?:/(menu-selected)/([^/]+)|)/?$ https://$host/indexpc.php?c1=$1&c2=$2&c3=$3&f_urlseo=1&f_idxt=cpn&$4=$5 
    }

    rewrite ^/?ld/([^/]+).*/?$      https://$host/ad_detail.php?ldasid=$1 permanent; 
  
    rewrite ^/?job/sales/location/([^/]+)/([^/]+)/([^/]+).*/?$   https://$host/users/jobs/job_sales.php?r2=$1&r3=$2&r4=$3 permanent; 

    
  https://$host/ect/gamesrc/javascript/tw/index_all_games.php [L,R=301]
    if ($host ~ "192.168.|172.20.|10.0."){ 
        rewrite ^/?games/?$ https://$host/ect/gamesrc/javascript/tw/index_all_games.php permanent;
    } 
    rewrite ^/?games/?$ https://$host/gamesrc/javascript/tw/index_all_games.php permanent;

  }
}

I have config file for AWS EBS like this:

packages:
  yum:
    sysstat: []
Resources:
  sslSecurityGroupIngress: 
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: {Ref : AWSEBSecurityGroup}
      IpProtocol: tcp
      ToPort: 443
      FromPort: 443
      CidrIp: 0.0.0.0/0
container_commands:
  01nginxrestart:
    command: "sudo service nginx restart" 

I can successfully deploy the website in AWS elastic bean stalk and run the website correctly. But nginx cannot find index.php a few days later maybe after the system reboot or something. When I initially and manually deploy the website in AWS EBS successfully, I run "systemctl status nginx.service", I get the following message. Is the first line warning "Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)" a concern at all?

● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/nginx.service.d
           └─nginx.conf
        /usr/lib/systemd/system/nginx.service.d
           └─php-fpm.conf
   Active: active (running) since Thu 2024-03-07 03:56:14 UTC; 2min 5s ago
  Process: 21877 ExecStopPost=/bin/sh -c rm -f /var/pids/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 21912 ExecStartPost=/bin/sh -c systemctl show -p MainPID nginx.service | cut -d= -f2 > /var/pids/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 21907 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 21904 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 21902 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 21909 (nginx)
   CGroup: /system.slice/nginx.service
           ├─21909 nginx: __ma_ster process /usr/sbin/nginx
           ├─21910 nginx: worker process
           └─21911 nginx: worker process

Mar 07 03:56:14 ip-172-31-37-27.us-west-2.compute.internal systemd[1]: Starting The nginx HTTP and reverse proxy server...
Mar 07 03:56:14 ip-172-31-37-27.us-west-2.compute.internal nginx[21904]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 07 03:56:14 ip-172-31-37-27.us-west-2.compute.internal nginx[21904]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 07 03:56:14 ip-172-31-37-27.us-west-2.compute.internal systemd[1]: Started The nginx HTTP and reverse proxy server.
jh5678
asked 2 months ago124 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions