间歇性“文件未找到。” nginx php(已解决)

间歇性“文件未找到。” nginx php(已解决)

当我访问我正在处理的 Web 应用程序的某些路径时,我会间歇性地收到“文件未找到”的错误信息。该错误显示在浏览器中,似乎不加区分地出现和消失 - 刷新页面通常有效,并且它似乎成群出现(例如,连续 10 次都返回错误,然后 20 次都没有问题)。

仅当尝试从 /run 位置访问文件或目录时才会发生此错误。我不确定这是因为 nginx 中的配置错误,还是因为在到达这些路由时加载了大量数据并导致其他问题。

我注意到的一件事是,当我遇到此问题时,访问日志没有被记录下来,而当页面按预期加载时,它确实被记录下来。我不确定这是否是预期的,但我觉得这很奇怪,因为输入了 uri,服务器必须被命中才能给出响应。

坦率地说,我甚至不确定这是服务器配置问题还是应用程序级别的问题,但基于网络选项卡显示当发生此错误时页面没有加载任何其他内容(/run 内的索引文件甚至没有加载,无论我尝试访问哪条路由,都只是 404)。

这些 nginx 配置文件中是否存在明显错误?我还应该在哪里查找,以便排除或缩小问题原因?

nginx.conf

user forge;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        server_names_hash_bucket_size 128;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

已启用站点/我的网站

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/my-website.com/before/*;

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

real_ip_header X-Forwarded-For;

server {
    listen 80;
    listen [::]:80;
    server_name mywebsite.com;

    if ($http_x_forwarded_proto != 'https') {
       return 301 https://$host$request_uri;
    }

    root /home/forge/mywebsite.com/public_html;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate;
    # ssl_certificate_key;

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    #add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php default.htm;

    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/mywebsite.com/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log /var/log/nginx/access.log custom;
    error_log  /var/log/nginx/mywebsite.com-error.log error;

    error_page 404 /index.php;

    client_max_body_size 128M;
    fastcgi_read_timeout 300;


    location ~ ^/(tam/mp3|cmbx/StagedStorage)/ {
        # add_header x-test-head downloads-block;
        default_type application/octet-stream;
        add_header Content-Disposition 'attachment;';
        disable_symlinks off;
    }

    location ~ ^/(tamXf|cmbx)/ {
        # add_header x-test-head tamXf-cmbx-block;
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;

            fastcgi_param PHP_VALUE "upload_max_filesize=0
                post_max_size=0
                max_input_time=0";
            client_max_body_size 0;
            fastcgi_read_timeout 1200;
        }
    }

    location /run {
        # Catch-all route that redirects to index.html
        include /etc/nginx/mime.types;
        try_files $uri $uri/ /run/index.html;

    }

    location ~ \.php$ {
        # add_header x-test-head catch-all-php-block;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

fastcgi_params

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_FILENAME     $request_filename;
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   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;
fastcgi_param   HTTPS           $https if_not_empty;
fastcgi_param   REDIRECT_STATUS     200;
fastcgi_param   HTTP_PROXY  "";

更新:有一个捕获所有块,它关闭了访问日志记录,我将其打开了,但仍然没有看到由于这个错误而填充的任何日志。

但是,该服务器是 AWS 上弹性负载均衡器的两个目标之一,跟踪第二台服务器的访问日志显示,在错误发生时条目正在填充。

相关内容