站点contactform.php具有不正确的文件权限 - nginx错误405(不允许)

时间:2017-03-14 15:27:16

标签: php nginx permissions

我联系了数字海洋支持团队,他们认为我的www / data文件具有不正确的文件权限

“此错误表示您网站中存在权限问题。您需要确保Web服务器用户最有可能访问使用该表单发送邮件所需的文件和应用程序的www数据。您应该能够在您网站的访问日志中跟踪尝试访问的确切文件名。“ - 数字海洋支持团队

我检查了nginx访问日志

  

70.54.134.32 - - [14 / Mar / 2017:14:58:34 +0000]“POST /contact_me.php HTTP / 1.1”405 584“https://cormaccrowley.com/”“Mozilla / 5.0   (Macintosh; Intel Mac OS X 10_12_2)AppleWebKit / 537.36(KHTML,如   Gecko)Chrome / 56.0.2924.87 Safari / 537.36“

我收到405不允许的错误 - contact_me.php文件权限

-rw-r--r-- 1 root root 1218 Mar 14 00:05 contact_me.php

这是我的PHP脚本

    <?php
// Check for empty fields
if(empty($_POST['name'])        ||
   empty($_POST['email'])       ||
   empty($_POST['phone'])       ||
   empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    echo "No arguments Provided!";
    return false;
   }

$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));

// Create the email and send the message
$to = 'c[MY-EMAIL-WAS-HERE]'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply@cormaccrowley.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>

Here is an image of the chrome inspect network window

1 个答案:

答案 0 :(得分:1)

目录中的文件需要由nginx正在运行的用户读取。您必须使用chown linux函数更改权限: chown www-data:www-data contact_me.php