NGINX:如何从img/file.jpg重定向到public/img/file.jpg



我有一个类似于以下的nginx配置:

server{
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/all-my-projects;
location / {
try_files $uri $uri/ =404;
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
}
location ~ .php$ {
fastcgi_pass $php_fastcgi_pass;
fastcgi_index /index.php;
include fastcgi_params;
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+?.php)(/.*)$;
try_files $fastcgi_script_name =404;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# These are the locations I'm havin' trouble
location /project {
try_files $uri @store-deprecated;
}
location @project {
rewrite /project/(.*)$ /project/public/index.php?_url=/$1 last;
}
}

但当我转到localhost/project时,浏览器上的图像不会加载到任何视图上。我知道当我转到project文件夹时,它会重定向到project/public/index.php并运行站点。

我把图像放在html中,如下所示:

<img src="img/image.png">

如何通过键入localhost/project/img/image.png来重写public/img/文件夹以访问所有图像?

cssjs文件夹以及favicon.ico也是如此

server {
rewrite ~ ^(/img/.*) /public$1 break;
}

相关内容

  • 没有找到相关文章

最新更新