关于前后端分离时无法访问服务端图片的nginx配置问题
目前项目是前后端分离的方式,但是出现的问题是访问
http://域名/storage/images/xxxx.jpg
这种存在于服务端文件夹的图片无法显示,提示404错误。
直接上nginx配置,求助一下大佬们哪里配置错误了,对nginx配置一直不是很熟悉。
#处理前端
server
{
listen 80;
server_name 域名;
index index.html index.htm index.php default.php default.htm default.html;
root /www/wwwroot/前端项目路径/build;
try_files $uri $uri/ /index.html;
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log /dev/null;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log /dev/null;
access_log off;
}
location /api/v1/{
#如果为/api/v1/开始则走php
proxy_pass http://localhost:9000;
}
location /storage {
root /www/wwwroot/后端项目路径/public/storage;
}
}
#处理php
server {
listen 9000;
server_name localhost;
root /www/wwwroot/后端项目路径/public/;
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi-74.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
我觉得问题出在
location /storage {
root /www/wwwroot/服务端/public/storage;
}
这个配置上面。
storage目录确定是有图片的,也有访问权限。但是不知道这个地方该如何配置。
推荐文章: