So I am having a problem with getting Nginx to serve static files for my Laravel app. I can see in chrome’s dev tools that the requests are being made to the path, where those files should be (http://mywebsite.com/public/css/style.css). But they are not being loaded at all. I’ve tried getting it to work in a lot of ways, but it just doesn’t seem to do the job. Could anyone help me with that? Cheers!
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’s a lot of files in /public directory that are not loading, but should be. Like for example css, js, html files for angular templates etc…
Advertisement
Answer
As Kyslik hinted, this could be a permission problem.
I had a similar problem, running Laravel on Homestead on Windows 10. In my case, I could access the files from publiccss
directory, but not from publiccssvendor
. I realized that I created the vendor
directory from Windows, and as a result, the files in it were not accessible by ngingx.
To fix the issue I deleted the vendor
directory and recreated it from within the vagrant box.