i am trying to serve images which are stored in different location other than document root.
#avatar files block
location ~^/pics/profile/(.*)$ {
alias /home/data/site_data/profile/$1;
}
i have added above code block in the nginx .conf
file and did
systemctl restart nginx
and when i tried to access
http://www.example.com/pics/profile/1/1.jpg
it gives me 404 not found error.
how can i fix this ?
i have specified document root at the top of nginx configuration
file like this
root /usr/share/nginx/site.com/html;
i have checked and the file exists at
/home/data/site_data/profile/1/1.jpg
update :
my full config is like this
server {
listen 80;
server_name example.com;
charset utf-8;
client_max_body_size 6M;
root /home/data/nginx/example.com/html;
location / {
index index.php index.html;
}
#error_page 403 404 500 502 503 504 /404.html;
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
access_log /dev/null;
#restrict php execution from these directories
location ^~ /cache/ {location ~* \.php$ { return 404; }}
location ^~ /content/ {location ~* \.php$ { return 404; }}
location ^~ /css/ {location ~* \.php$ { return 404; }}
location ^~ /images/ {location ~* \.php$ { return 404; }}
location ^~ /js/ {location ~* \.php$ { return 404; }}
location ^~ /pics/ {location ~* \.php$ { return 404; }}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.(php)$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#avatar files block
location ~^/pics/profile/(.*)$ {
alias /home/data/site_data/profile/$1;
}
include /etc/nginx/example.com_rewrite_rules.conf;
}