Flask服务器-有效端点大约有一半的时间出现404错误

时间:2020-05-16 08:26:39

标签: nginx server http-status-code-404 gunicorn nginx-config

nginx有一个非常奇怪的问题:我在AWS服务器上使用Python运行一个非常基本的flask / gunicorn应用程序,并且我对有效端点的许多请求都收到404(大约一半)。

我已经做了一些尝试来将问题隔离到nginx。我翻阅了

/var/log/nginx/access.log

这是输出:

24.21.97.98 - - [16/May/2020:08:15:10 +0000] "GET / HTTP/1.1" 200 53 "-" "PostmanRuntime/7.24.1"
24.21.97.98 - - [16/May/2020:08:15:11 +0000] "GET / HTTP/1.1" 200 53 "-" "PostmanRuntime/7.24.1"
24.21.97.98 - - [16/May/2020:08:15:12 +0000] "GET / HTTP/1.1" 200 53 "-" "PostmanRuntime/7.24.1"
24.21.97.98 - - [16/May/2020:08:15:13 +0000] "GET / HTTP/1.1" 200 53 "-" "PostmanRuntime/7.24.1"
24.21.97.98 - - [16/May/2020:08:15:13 +0000] "GET / HTTP/1.1" 404 209 "-" "PostmanRuntime/7.24.1"
24.21.97.98 - - [16/May/2020:08:15:16 +0000] "GET / HTTP/1.1" 200 53 "-" "PostmanRuntime/7.24.1"
24.21.97.98 - - [16/May/2020:08:15:16 +0000] "GET / HTTP/1.1" 404 209 "-" "PostmanRuntime/7.24.1"
24.21.97.98 - - [16/May/2020:08:18:32 +0000] "GET / HTTP/1.1" 301 194 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:33 +0000] "GET / HTTP/1.1" 200 53 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:33 +0000] "GET /favicon.ico HTTP/1.1" 404 209 "https://example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:34 +0000] "GET / HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:38 +0000] "GET / HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:39 +0000] "GET / HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:39 +0000] "GET / HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:40 +0000] "GET / HTTP/1.1" 200 53 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:41 +0000] "GET / HTTP/1.1" 200 53 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:42 +0000] "GET / HTTP/1.1" 200 53 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
24.21.97.98 - - [16/May/2020:08:18:43 +0000] "GET / HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"

在此代码中,我反复向/路由发出GET请求,该请求仅返回一个字符串。我调查了404 209,但无法准确确定为什么会偶然发生此错误。该服务器在一个AWS实例上运行,只有一小部分用户,当时没有人提出请求。

错误日志(位于/var/log/nginx/error.log)为空。

这是我当前用于nginx的.conf文件:

server {
        listen 443 ssl;
        listen [::]:443 ssl;

        server_name DOMAIN.com www.DOMAIN.com;

        location / {
                proxy_pass http://127.0.0.1:8000/;
        }

    ssl_certificate /etc/letsencrypt/live/DOMAIN.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/DOMAIN.com/privkey.pem; # managed by Certbot

}

server {
    if ($host = www.DOMAIN.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = DOMAIN.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

        listen 80;
        listen [::]:80;

        server_name DOMAIN.com www.DOMAIN.com;

        return 301 https://$server_name$request_uri;

}

有什么提示吗?谢谢!

0 个答案:

没有答案