NGINX+wordpress:CSS 正在提供但未套用

NGINX+wordpress:CSS 正在提供但未套用

各位堆高機乾杯,

我有點必須讓 wordpress 在自架 nginx 環境中運作。

或多或少完全使用建議的配置NGINX WordPress 文檔

server {
    listen 443 ssl;
    server_name _;
    ssl_certificate /var/lib/nginx/PKI/www/server/cert.pem;
    ssl_certificate_key /var/lib/nginx/PKI/www/server/key.pem;
    root /var/lib/nginx/www/wordpress;
    index index.php;
    location / {
            try_files $uri uri/ /index.php?$args;

    }
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_intercept_errors on;
        fastcgi_pass php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
    }
}

除了樣式之外,一切基本上都如預期進行。網站上似乎沒有套用任何樣式(也適用於管理員登入/快速啟動精靈)。

在管理儀表板內部,一切看起來都很好。

NGINX 正在正確提供 CSS 檔案。

答案1

我的 nginx 配置不包括 mime.types 預設值。

這似乎影響了 nginx“Content-Type”回應標頭,導致它是“text/plain”而不是“text/css”...

……這是不幸的,因為沒有一個 WordPress 模板指定請求中的內容類型,例如:

<link rel='stylesheet' id='wp-block-library-css'  href='https://censored.net/wp-includes/css/dist/block-library/style.css?ver=5.8' media='all' />

可能看起來像這樣,但是哦,好吧

<link rel="styleseeht" type="text/css" ...>

相關內容