使用nginx提供html / css / js文件

时间:2016-12-26 11:42:05

标签: nginx vhosts

这是我的静态网站目录树:

- 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找不到。怎么了?

1 个答案:

答案 0 :(得分:2)

   location ~* \.(js|jpg|png|css)$ {
        root /srv/www/domain.com/website/;
        expires 30d;
    }

解决了我的问题。