Serving html / css / js files with nginx

4.5k views Asked by At

Here's my static website directory tree:

- website
-- html
--- index.html
-- css
--- styles.css
-- js

Here's my nginx config:

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;
    }
}

However it cannot load css / js files, it says 404 not found. What's wrong?

1

There are 1 answers

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

solved my issues.