0

我有一个像这样的 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">

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

与 acssjs文件夹和 a相同favicon.ico

4

1 回答 1

0
server {
  rewrite ~ ^(/img/.*) /public$1 break;
}
于 2021-12-18T19:36:45.390 回答