我正在使用 nginx 在 AWS Ubuntu EC2 上开发一个具有 Angular 前端和 Lumen 后端的网站。当我尝试向登录 API 端点发出 POST 命令时,它给了我一个“405 Not Allowed”错误,我不知道为什么,我迫切需要比我更了解的人的帮助。
这是我用于 nginx 服务器的代码
server {
listen 80;
listen [::]:80;
server_name ~~~~~~~~.compute-1.amazonaws.com;
server_tokens off;
client_max_body_size 10M;
location = /assets/favicon.ico {
access_log off; log_not_found off;
}
# The front end Angular
location / {
root /var/www/html;
index index.html;
try_files $uri $uri/ /index.html =404;
}
location /files/ {
root /var/www/html/files;
}
# The lumen API
location /api/ {
error_log /var/log/nginx/error.log debug;
root /var/www/html/api/public;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
}
(注意:我通常包含安全标头,但将其关闭以尝试隔离问题。此外,我还没有为此站点设置 SSL 证书)
当我尝试发布到“/api/auth/login”(或任何 api 端点)时,这就是 nginx 错误日志输出的内容:
2023/02/25 00:59:24 [debug] 371832#371832: *8 http cl:181 max:10485760
2023/02/25 00:59:24 [debug] 371832#371832: *8 rewrite phase: 3
2023/02/25 00:59:24 [debug] 371832#371832: *8 post rewrite phase: 4
2023/02/25 00:59:24 [debug] 371832#371832: *8 generic phase: 5
2023/02/25 00:59:24 [debug] 371832#371832: *8 generic phase: 6
2023/02/25 00:59:24 [debug] 371832#371832: *8 generic phase: 7
2023/02/25 00:59:24 [debug] 371832#371832: *8 access phase: 8
2023/02/25 00:59:24 [debug] 371832#371832: *8 access phase: 9
2023/02/25 00:59:24 [debug] 371832#371832: *8 access phase: 10
2023/02/25 00:59:24 [debug] 371832#371832: *8 post access phase: 11
2023/02/25 00:59:24 [debug] 371832#371832: *8 generic phase: 12
2023/02/25 00:59:24 [debug] 371832#371832: *8 try files handler
2023/02/25 00:59:24 [debug] 371832#371832: *8 http script var: "/api/auth/login"
2023/02/25 00:59:24 [debug] 371832#371832: *8 trying to use file: "/api/auth/login" "/var/www/html/api/public/api/auth/login"
2023/02/25 00:59:24 [debug] 371832#371832: *8 http script var: "/api/auth/login"
2023/02/25 00:59:24 [debug] 371832#371832: *8 trying to use dir: "/api/auth/login" "/var/www/html/api/public/api/auth/login"
2023/02/25 00:59:24 [debug] 371832#371832: *8 http script copy: "/index.php?"
2023/02/25 00:59:24 [debug] 371832#371832: *8 trying to use file: "/index.php?" "/var/www/html/api/public/index.php?"
2023/02/25 00:59:24 [debug] 371832#371832: *8 internal redirect: "/index.php?"
我从网络服务器得到的只是 405 错误。
我已经尝试了上述各种不同的排列,但我似乎无法找到能够解决此 405 错误的排列。我找错地方了吗?
当我运行它时,它在本地工作,但在服务器上不工作。
我仔细检查了数据库权限设置是否正确。
我再次检查 /api/auth/login 的路由没有通过任何类型的身份验证中间件。
我现在筋疲力尽,情绪一团糟,因为我无法让它工作,而且我无法在互联网上找到解决方案。我发誓它昨天还在工作,但我所做的任何更改都完全破坏了它。
有人可以告诉我我做错了什么,或者至少提示还有什么要检查的,因为我对此失去了理智。