nginx - 在 nginx 中获取别名重定向规则的 500 内部错误
问题描述
我是 nginx 服务器的新手。我陷入了 URL 重定向。我对默认文件有以下几行。
server {
listen 80;
root /home/ubuntu/web/server/current/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
error_log /home/ubuntu/web/error.log info;
location / {
# try_files $uri $uri/ /index.php?$query_string;
# try_files $uri $uri/ =404;
}
rewrite ^/web/(.*) /web/;
location /web/ {
alias /home/ubuntu/web/client/web/;
# try_files $uri $uri/ index.html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
我对上述重写规则的期望是 - 所有 URL,如 - http://example.com/web/login,http://exmpale.com/web/dashboard将被重定向到 /home/ubuntu/web/client/web / 并且要点击的默认页面是 index.html 文件。
当我打开错误日志文件时,我发现了类似的错误 -
重写或内部重定向循环,同时内部重定向到“/web/index.php”,客户端:ip_address,服务器:_,请求:“GET /web/ HTTP/1.1”,主机:“ipaddress”
我在这里做错了什么。
解决方案
答案归功于@RichardSmith,他提供了正确方向的可能错误。我发现我在 nginx 重写规则中的错误。
rewrite ^/web/(.*) /web/;
location /web/ {
alias /home/ubuntu/web/client/web/;
# try_files $uri $uri/ index.html;
}
而不是上面我应该有以下 -
rewrite ^/web/(.*) web/;
location web/ {
alias /home/ubuntu/web/client/web/;
# try_files $uri $uri/ index.html;
}
/
无论何时放置在 web 之前,服务器都将路径视为绝对路径 。因此rewrite
语句尝试重定向到绝对路径中不存在的后备文件。最终,rewrite
语句使永无止境的循环。
推荐阅读
- tensorflow - 为什么“使用比嵌入层后面的层中的单元数更多的嵌入维度会很浪费”
- git - 错误 404 KeyNotFound 和缺少文件 git - s3 部署
- html - 我试图在 HTML5 中创建一个 4 列的行,但列显示一个在另一个下而不是并排
- php - 为什么我会出现此错误:“数组”第 2 行或附近的语法错误:值数组?
- python - 如何从文件中读取文件路径并创建单个组合数据框?
- javascript - 将数据传递给父组件时是否需要提升状态?
- sockets - 我可以设置 QoS 2 和 ToS 16 的全局默认值以应用于例如 gSOAP 服务吗?
- angular - 错误当我使用时,位置 2 出现了意外的文字
来自 Angular 9 中的 PrimeNG - java - 向下滑动金字塔时位移以决定左或右方向
- python - 在 Django 站点上运行服务器命令时出现属性错误