这是我的静态网站目录树:
- website
-- html
--- index.html
-- css
--- styles.css
-- js
这是我的nginx配置:
server {
listen 80;
root /srv/www/domain.com/website/html;
index index.php index.html index.htm;
server_name domain.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
然而它无法加载css / js文件,它说404找不到。怎么了?
答案 0 :(得分:2)
location ~* \.(js|jpg|png|css)$ {
root /srv/www/domain.com/website/;
expires 30d;
}
解决了我的问题。