Nginx上的Magento 2.4找不到CSS和JS文件

Nginx上的Magento 2.4找不到CSS和JS文件,nginx,magento2,Nginx,Magento2,我已经试了三天了,但是我不能让它工作。我成功地安装了Magento和所有东西,但当我访问该网站时,找不到所有CSS和JS文件 当我查看请求时,url中总是有/versionxxxxx/,因此重写可能没有正确设置 我尝试将此代码添加到我的服务器块: location /static/ { # Uncomment the following line in production mode # expires max; # Remove signature of the st

我已经试了三天了,但是我不能让它工作。我成功地安装了Magento和所有东西,但当我访问该网站时,找不到所有CSS和JS文件

当我查看请求时,url中总是有/versionxxxxx/,因此重写可能没有正确设置

我尝试将此代码添加到我的服务器块:

location /static/ {
    # Uncomment the following line in production mode
    # expires max;

    # Remove signature of the static files that is used to overcome the browser cache
    location ~ ^/static/version {
        rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
    }

    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|html|json)$ {
        add_header Cache-Control "public";
        add_header X-Frame-Options "SAMEORIGIN";
        expires +1y;

        if (!-f $request_filename) {
            rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
        add_header Cache-Control "no-store";
        add_header X-Frame-Options "SAMEORIGIN";
        expires    off;

        if (!-f $request_filename) {
           rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    if (!-f $request_filename) {
        rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
    }
    add_header X-Frame-Options "SAMEORIGIN";
}
但不幸的是,所有文件仍然返回一个404未找到。 示例文件:

/pub/static/version1600350960/frontend/Magento/luma/en_US/requirejs/require.js

文件确实存在于我的FTP上的正确目录中,但“版本”名称不在该目录中


有人能帮我吗,因为我不知道如何在NGINX中解决这个问题。

尝试删除最后一个
if
块。这确实解决了问题,Richard,非常感谢!我现在唯一的(新)问题是,当我进入一个新页面时,即,我会抛出一个404 NOT FOUND错误:(