Laravel and Nginx static files

So I am having a problem getting Nginx to serve static files for my Laravel application. I can see in the chrome dev tools that requests are made to the path where these files should be ( http://mywebsite.com/public/css/style.css ). But they don't load at all. I've tried to get it to work in many ways, but it just doesn't work. Can anyone help me with this? Hooray!

  server {

    listen 80;

    server_name mydomainname.com;

    keepalive_timeout   70;
    root /var/www/html/portfolio/public;
    index index.php index.html index.htm index.nginx-debian.html;
    autoindex on;

    charset utf-8;

    location / {
        root   /var/www/html/portfolio/public;
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/myapp-error.log error;

    sendfile on;

    client_max_body_size 100m;

    rewrite ^ /index.php last;

    location ~ \.php$ {
        try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    location ~ /\.ht {
        deny all;
    }
}

      

Basically, there are a lot of files in the / public directory that won't load but should be. Like css, js, html files for angular templates etc ...

+3


source to share


2 answers


URLs must not include the part /public

in the path. /public

is the root of your web resources. Therefore, your url should be:



http://mywebsite.com/css/style.css

      

0


source


As Kyslik hinted, this could be a permission issue.

I had a similar problem running Laravel on Homestead on Windows 10. In my case, I could access files from a directory public\css

, but not from public\css\vendor

. I realized that I had created a directory vendor

from Windows, and as a result, the files in it were not available to ngingx.



To fix the problem, I deleted the directory vendor

and recreated it from the vagrant window.

0


source







All Articles