我的鹈鹕博客上有一个简单的联系页面。
联系页面使用js向PHP脚本发送POST请求,该脚本执行SMTP请求以发送电子邮件。当我在网络浏览器上尝试这个时它不起作用,如果我使用curl,我会收到405错误:
✗ curl -H "Content-Type: application/json" -X POST -d '{"name":"PM","email":"p@m.com", "message":"foo"}' https://pm.com/theme/send-form.php
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.10.3 (Ubuntu)</center>
</body>
</html>
我的nginx位置指令如下所示:
location / {
# Serve a .gz version if it exists
gzip_static on;
# Try to serve the clean url version first
try_files $uri.html $uri.html $uri =404;
# allow POST on static pages
error_page 405 =200 $uri;
}
location ~ \.php$ {
# If a file isn't found, 404
try_files $uri =404;
#Include Nginx's fastcgi configuration
include /etc/nginx/fastcgi.conf;
#Look for the FastCGI Process Manager
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
我从https://linuxconfig.org/basic-php-7-and-nginx-configuration-on-ubuntu-16-04-linux
获取了此位置指令的灵感然而,它仍然无法正常工作,最令人烦恼的是,在任何nginx访问/错误日志或php7.0-fpm错误日志中都没有任何错误的证据。