Valet: 404 for files in public/ (LaravelValetDriver)

Created on 11 May 2017  Â·  13Comments  Â·  Source: laravel/valet

I always get a status code 404 for existing files which are directly located under public/ on a fresh install (favicon.ico, robots.txt), but the files are delivered. If I name them differently, it's working with a 200. Files in subdirectories css/, js/ are served properly with a status code 200.

Edit: I figured out that the problem is located in the Nginx config. If I comment out these lines, favicon.ico and robots.txt are served.

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

Most helpful comment

Also stumbled on this issue today, here is my workaround for now:

Nginx is looking for a _favicon.ico_ file at the root level.
Instead, for Laravel projects, it should look in the public folder.

Just add /public on the files paths inside your config file, and run valet restart:

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

If you have run valet secure, you'll find your app's config file here: ~/.config/valet/nginx/your_app.test

Otherwise, the default valet nginx config file is located here:
/usr/local/etc/nginx/valet/valet.conf

It might make more sense to edit it on a project basis, in case you don't only serve Laravel apps with Valet.

All 13 comments

I just spent half an hour trying to figure out what was wrong with my favicon for my new spark project served behind valet. I'd be happy to figure out how to patch this if someone could point me in the right direction.

I feel like I fixed this on the master branch a few months back, are you
running dev-master or latest tag?
On Tue, Sep 12, 2017 at 6:08 PM Beau Simensen notifications@github.com
wrote:

I just spent half an hour trying to figure out what was wrong with my
favicon for my new spark project served behind valet. I'd be happy to
figure out how to patch this if someone could point me in the right
direction.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel/valet/issues/375#issuecomment-328998407, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AEH3bFK6c7UK0fCCYvDX-9Uf47iBz2O1ks5shwDLgaJpZM4NYQX5
.

hm. let me see. it looks like i was one version back. the problem i'm having might be slightly different. commenting out the lines mentioned above didn't fix my problem. my problem is that getting /favicon.ico returns the actual image but gives status 404. so if i visit /favicon.ico in the browser directly, it renders just fine.

Yeah that should be fixed, but if you are using local SSL on that site you'll need to resecure that site to generate an updated nginx config.

Quick trick to regenerate configs for any SSL sites:

valet domain blah
valet domain dev

cool, thanks. i'm not doing local ssl. or rather, wasn't. just tried "valet secure mudskipper-dev" and it worked like a charm. loving valet even more now. :) thanks for your help!

also, for the record, i did an update from valet v2.0.4 to v2.0.5 and it all looks good now.

Sweet!

I'm still having this issue. Just upgraded to v2.8.1 and still favicon.ico and my https://project.test/ is giving a 404 error on favicon, but opening https://project.test/favicon.ico directly does seem to work.

It seems the issue with favicon.ico / robots.txt was fixed in this commit (v2.0.5) but was later re-introduced in #819 (v2.4.1). To work around this I have removed the favicon.ico and robots.txt location blocks from my Nginx configuration.

I'm having the same issue.

@stidges Great catch there. That's a fascinating issue... I'm curious how we can get rid of the error logs but also make it work

I'm not a nginx expert unfortunately but what happens if you only have
location = /favicon.ico { access_log off } ?
So only turning off access logging but not error log? All sites should have a working favicon these days anyway else they will see 404 errors when the site goes live.

Also stumbled on this issue today, here is my workaround for now:

Nginx is looking for a _favicon.ico_ file at the root level.
Instead, for Laravel projects, it should look in the public folder.

Just add /public on the files paths inside your config file, and run valet restart:

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

If you have run valet secure, you'll find your app's config file here: ~/.config/valet/nginx/your_app.test

Otherwise, the default valet nginx config file is located here:
/usr/local/etc/nginx/valet/valet.conf

It might make more sense to edit it on a project basis, in case you don't only serve Laravel apps with Valet.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eberkund picture eberkund  Â·  4Comments

tommytompkins picture tommytompkins  Â·  4Comments

dannygsmith picture dannygsmith  Â·  5Comments

EHLOVader picture EHLOVader  Â·  4Comments

idmahbub picture idmahbub  Â·  3Comments