[英]NGINX: How to redirect from img/file.jpg to 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;
}
}
但是当我 go 到localhost/project
时,浏览器上的图像不会加载到任何视图上。 我知道我在 go 到project
文件夹时重写了,它重定向到project/public/index.php
并运行该站点。
我将图像放在 html 中,如下所示:
<img src="img/image.png">
如何通过键入localhost/project/img/image.png
重写public/img/
文件夹以访问所有图像?
与css
和js
文件夹以及favicon.ico
相同
server {
rewrite ~ ^(/img/.*) /public$1 break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.