I have the following issue which I can't seem to wrap my head around.
All images assets uploaded to Craft return a 404 not found on the front-end. Everything works fine in the admin CP though (uploading, renaming, thumbnails, etc.). Any template with getUrl() outputs the correct URL but the resource returns a 404 status code. When I navigate directly to the asset's URL, Craft returns a 404 template instead of the image.
These are the things I have checked so far :
- Files permissions seem OK (775 on folder and 664 on files) on the "craft" user;
- The assets paths is
{basePath}uploads/images/ - The assets URL is
{siteUrl}images/ - Both
{basePath}and{siteUrl}are correctly set as environment variables ingeneral.php - I'm running Nginx with a config similar to this answer
Any thoughts ? This is really bugging me.
Thanks.
Edit
These are my two nginx configuration files :
# nginx.conf
user craft craft;
worker_processes auto;
worker_rlimit_nofile 8192;
events {
worker_connections 8000;
}
error_log /var/log/nginx/error.log debug; # not for production
pid /var/run/nginx.pid;
http {
disable_symlinks off;
proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 2048 8k;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
rewrite_log on;
access_log /var/log/nginx/access.log;
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
sendfile on;
tcp_nopush on;
gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_disable "msie6";
include /etc/nginx/sites-enabled/*;
}
and
# site.conf
# -------------------------------------------------
# General server configuration
server {
listen 80 default_server;
server_name example.com;
root /srv/craft/public;
index index.php index.html index.htm;
charset utf-8;
error_page 404 /index.php;
error_log /var/log/nginx/example.com.error.log debug;
access_log /var/log/nginx/example.com.access.log;
# -------------------------------------------------
# Some locations to help during dev, remove for production
location = /phpinfo {
try_files $uri $uri/ /phpinfo.php$is_args$args;
}
location = /status {
access_log off;
allow all;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /status;
fastcgi_pass unix:/var/run/php-fpm.sock;
}
location = /ping {
access_log off;
allow all;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /ping;
fastcgi_pass unix:/var/run/php-fpm.sock;
}
# -------------------------------------------------
# Static assets (css, js, fonts, etc.) location
location /src {
root /srv/craft/public/src;
expires 1y;
access_log off;
add_header Pragma public;
add_header Cache-Control "public";
}
# -------------------------------------------------
# Craft application locations
location / {
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^(.*) /index.php?p=$1 last;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
try_files $uri /index.php?$query_string;
expires -1;
}
# Feed
location ~* \.(?:rss|atom)$ {
try_files $uri /index.php?$query_string;
expires 1h;
add_header Cache-Control "public";
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|pdf|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
try_files $uri /index.php?$query_string;
expires 1M;
add_header Pragma public;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
try_files $uri /index.php?$query_string;
expires 1y;
add_header Pragma public;
add_header Cache-Control "public";
}
# -------------------------------------------------
# Other static ressources
# Favicons
location = /favicon.ico {
access_log off;
log_not_found off;
}
# Robots.txt
location = /robots.txt {
access_log off;
log_not_found off;
}
# Humans.txt
location = /humans.txt {
access_log off;
log_not_found off;
}
# Prevent clients from accessing hidden files (starting with a dot)
# This is particularly important if you store .htpasswd files in the site hierarchy
location ~* (?:^|/)\. {
deny all;
}
# Prevent clients from accessing to backup/config/source files
location ~* (?:\.(?:bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$ {
deny all;
}
}
{siteUrl}uploads/images? – megatrond Jan 14 '16 at 19:00/srv/craft/public. I would guess your URLs are coming out likewhatever.com/images/when they should be coming out likewhatever.com/uploads/images. – RitterKnight Jan 14 '16 at 22:15location /imagesblock, the root you mention would serve it out of that directory and nginx would use files in that location when it encounters something fromwhatever.com/images/. – RitterKnight Jan 14 '16 at 22:33