nginx - nginx 限制或重定向请求通过根目录中的 index.php
问题描述
我的项目要求是从 Slim 框架 (index.php) 启动一个 angular(v6)/ionic(v4) 应用程序(index.html)。根文件夹结构如下图所示:
'www' 是 Slim index.php 所在的根目录。在“www”内是添加了角度构建文件(index.php)的应用程序文件夹。要求是所有请求都应该通过根文件夹中的 Slim index.php,并且基于一些会话逻辑,我们必须路由或启动 Angular 应用程序(index.html)。
现在,“ https://domain/ ”通过 index.php。但是,“ https://domain/app/ ”直接启动 Angular 应用程序 (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;
}
}
谢谢
解决方案
您可以像这样限制对app
目录的访问
location /app {
deny all;
return 404; #show not found instead of 403
}
或者您可以通过发送重定向来覆盖 403 处理https://example.com/
location /app{
deny all;
error_page 403 https:/domain.com/; #redirect to your main directory
}
推荐阅读
- c# - 如果执行 Task.Run 是一种不好的做法,库如何提供异步方法?
- ssas - 基于另一个维度的 DAX 加权平均值
- bash - 防止 bash 完成打印两次回复
- firebase - 使用 FirestoreDocument
- spring-mvc - 创建自定义错误处理程序时如何将错误详细信息传递给模型?
- python-3.x - 编写带有散点图的文本
- angular - 在 ng-select 中隐藏选择
- vba - 使用 Visual Basic 和用户窗体将文件夹中的多个文件内容提取到一个文件中以选择文件夹
- javascript - 虽然使用 jspdf标签将 html 转换为 pdf 不起作用,但只有文本会被转换
- android - 当我在弹出窗口中单击微调器时,活动完成