簡體   English   中英

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

[英]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/文件夾以訪問所有圖像?

cssjs文件夾以及favicon.ico相同

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM