URL上的NGINX加载静态内容

URL上的NGINX加载静态内容,nginx,url,static,overriding,Nginx,Url,Static,Overriding,使用以下nginx配置,如果请求url/intern,我尝试加载静态内容,但在404中尝试失败。我如何为这种情况正确设置nginx server { listen 80; root /var/www/html/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$

使用以下nginx配置,如果请求url
/intern
,我尝试加载静态内容,但在404中尝试失败。我如何为这种情况正确设置nginx

server {
  listen 80;
  root /var/www/html/public;
  index index.php index.html index.htm;

  location / {
     try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
      include fastcgi_params;
      #try_files $uri /index.php =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass php:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
  
    location = /intern {
       autoindex on;
       root /var/www/html/public/back;
    }
}

root
指令的情况下,将完整路径附加到包含位置部分的根,而在
alias
指令的情况下,仅将不包含位置部分的路径部分附加到别名

因此:

 location = /intern/ {
       autoindex on;
       root /var/www/html/public/back;
    }
nginx将创建最终路径:

/var/www/html/public/back/intern/*

假设在
../public/back/
目录中没有
intern
目录,这将导致404错误。 如果是这种情况,您应该使用
alias
指令。在所述位置查找文件之前,位置路径已被删除

试试这个:

location = /intern/ {
       autoindex on;
       alias /var/www/html/public/back/;  # trailing slash is important here
    }
这将导致以下路径:

/var/www/html/public/back/*

感谢您的反馈,我按照您的建议尝试了alias,但仍然无法正确映射目录,因为我得到了404。您能否检查/共享文件
/var/log/nginx/error.log
中的nginx错误日志?