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
}

相關內容