
问题描述
项目中所有的资源放在/www/jianshu/public/storage中,希望通过url的方式将其展示出来,如下是配置
eg: http://demo.test.com/storage/img/1.pngserver
{
listen 80;
listen [::]:80;
server_name demo.test.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/test/public;
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-74.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /server/vhost/rewrite/demo.test.com.conf;
#REWRITE-END
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log /dev/null;
}
access_log /wwwlogs/demo.test.com.log;
error_log /wwwlogs/demo.test.com.error.log;
}按照如上配置访问时,返回404
解决问题
新增资源访问配置
location ^~ /storage/ {
alias /www/test/public/storage/;
}总结
root响应的路径:配置的路径(root指向的路径)+完整访问路径(location的路径)+静态文件
alias响应的路径:配置路径+静态文件(去除location中配置的路径)
评论
暂无评论
评论(10)