AWS Elastic Beanstalk nginx is down after a few days

0

My website in AWS Elastic Beanstalk is running ok after installation in php 8.1 using nginx. However a few days later the website is down due to nginx error.

The error message on webpage after nginx fails is :

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.

I have to re-deploy the package to make the website running (sometimes restart nginx will do the job). But a few days (7 days) later the same error occurs again. What is the issue and how to fix it ?

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;
    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" 

Someone say this may be related to the maintenance window in ElasticBeanstalk.

I read another thread about nginx issue. And it is about reload(), restart () and force-reload. But I do not quite sure what does that means and how to fix it for Elastic Beanstalk deployment. The thread is : https://stackoverflow.com/questions/49446522/nginx-process-is-dead-why-and-where-to-look

Do you have any idea on how to fix this nginx issue ?

jh5678
asked 5 months ago113 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