简体   繁体   English

为什么我收到 nginx 的不允许错误?

[英]why am I Getting a not allowed error with nginx?

I have a 405 not allowed when i request any.html or.php with POST method.当我使用 POST 方法请求 any.html 或 .php 时,我有一个 405 不允许。 im using a windows 10 machine and wsl2 with ubuntu terminal.我使用的是 windows 10 机器和带有 ubuntu 终端的 wsl2。 this never happened when i used my dual booted ubuntu.这在我使用双启动 ubuntu 时从未发生过。 why is this happening.为什么会这样。

By default NGINX does not allow POST requests to static files (such as.html).默认情况下 NGINX 不允许对 static 文件(例如 .html)的 POST 请求。 There is a well-known hack to overcome this:有一个众所周知的 hack 可以克服这个问题:

  error_page 405 =200 $uri;

It works by replacing 405 return code with 200 and serving the request instead of error page.它通过用 200 替换 405 返回码并提供请求而不是错误页面来工作。 Place it in a location when you want to allow POST requests to static files.当您希望允许对 static 文件发出 POST 请求时,请将其放置在某个位置。

As for php you probably haven't configured an interpreter for scripts.至于php您可能还没有为脚本配置解释器。 Without proper configuration NGINX will show php files as plain text files.如果没有正确配置 NGINX 将php文件显示为纯文本文件。 Here is an example how nginx can be configured for php-fpm . 是一个如何为php-fpm配置 nginx 的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM