[英]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.