首页 文章

nginx限制或重定向请求以通过root中的index.php

提问于
浏览
1

我的项目要求是从Slim框架(index.php)启动一个角度(v6)/离子(v4)应用程序(index.html) . 根文件夹结构附在下图中:

'www'是Slim index.php所在的根目录 . 里面的'www'是添加了角度构建文件(index.php)的app文件夹 . 要求是所有请求都应该通过根文件夹中的Slim index.php并基于我们必须路由或启动角度应用程序(index.html)的一些会话逻辑 .

现在,'https://domain/ ' goes through index.php. But, ' https://domain/app/'直接启动角度应用程序(index.html) .

如何配置nginx以便Slim index.php在根目录中处理所有请求?

server {
    server_name <domain>;

    root /var/www/<some name>/public/www/;
    index index.php index.html index.htm;

    access_log  /var/log/nginx/<some name>.log;
    error_log   /var/log/nginx/<some name>.log;

    sendfile off;

    location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ index.php /index.php?$args;
    }
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_read_timeout 36000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

谢谢

1 回答

  • 1

    你可以像这样限制对 app 目录的访问

    location /app {
        deny all;
        return 404; #show not found instead of 403
    }
    

    或者您可以通过向 https://example.com/ 发送重定向来覆盖403处理

    location /app{
         deny all;
         error_page 403 https:/domain.com/;  #redirect to your main directory
     }
    

相关问题