这是我当前的 Nginx 配置,我的问题是 404 页面不提供 CSS,如果我将 CSS 文件放入,它会提供 CSS /var/www/testdoamincom
,但在其他情况下它都不提供服务,有什么办法可以让我的404error
页面及其CSS
文件与我的其他网站文件分开,但仍然可以获得 CSS?
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name test.domain.com;
root /var/www/testdoamincom;
index index.php index.html index.htm;
# SSL Configuration Start
ssl_certificate /etc/ssl/certs/cloudflare_mydomain.com.pem;
ssl_certificate_key /etc/ssl/private/cloudflare_mydomain.com.pem;
ssl_client_certificate /etc/ssl/certs/origin-pull-ca.pem;
ssl_verify_client on;
client_max_body_size 100M;
# SSL Configuration End
# Error Pages Start
location / {
try_files $uri $uri/ =404;
}
error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 /404.html;
location = /404.html {
root /var/www/html;
}
# Error Pages End
location ~ \.php$ {
include /etc/nginx/mime.types;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
答案1
这是修复;
location ~* \.(js|jpg|png|css)$ {
root /path/to/your/css/files;
expires 30d;
}