Nginx 代理下载文件时不使用“http://”

Nginx 代理下载文件时不使用“http://”

我使用 Laravel API 和 NuxtJS (SSR) 创建了一个项目

将其部署在运行 Ubuntu (18.04 LTS) 的 AWS 服务器上。我的问题是,每当我转到链接“example.com”时,它都会下载一个文件,但每当我添加例如 http:// 或 https:// 时,它都会正常工作。

这是我的服务器块:

# Default

map $sent_http_content_type $expires {
        "text/html"                     epoch;
        "text/html; charset=utf-8"      epoch;
        default                         off;
}

server {
    # listen [::]:80 ssl http2;
    server_name example.com www.example.com;

    gzip            on;
    gzip_types      text/plain application/xml text/css application/javascript;
    gzip_min_length 1000;

    # Logs
    access_log /var/log/nginx/example.com_access.log;
    error_log /var/log/nginx/example.com_error.log;

    location / {

        expires $expires;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass                          http://127.0.0.1:3000;
        proxy_http_version                  1.1;
        proxy_set_header                    upgrade $http_upgrade;
        proxy_set_header                    Connection 'upgrade';
        proxy_set_header                    Host $host;
        proxy_cache_bypass                  $http_upgrade;

        proxy_redirect                      off;

    }

    location ~ /\.{
        access_log off;
        log_not_found off;
        deny all;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

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


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


    listen 80 http2;
    server_name example.com www.example.com;
    return 404; # managed by Certbot
}

答案1

通过更改修复

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


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


    listen 80 http2;
    server_name example.com www.example.com;
    return 404; # managed by Certbot
}

到:

server {
    listen 80 default_server;

    server_name example.com www.example.com

    return 301 https://$host$request_uri
}

相关内容