【问题标题】:Site contactform.php has incorrect file permissions - nginx error 405 (not allowed)站点 contactform.php 文件权限不正确 - nginx 错误 405(不允许)
【发布时间】:2017-03-14 15:27:16
【问题描述】:

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

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

我检查了 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;英特尔 Mac OS X 10_12_2)AppleWebKit/537.36(KHTML,如 壁虎)Chrome/56.0.2924.87 Safari/537.36"

我收到 405 not allowed 错误 - 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;            
?>

【问题讨论】:

    标签: php nginx permissions


    【解决方案1】:

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

    【讨论】:

    • 我刚试过,得到了chown: invalid user: ‘nginx:nginx’
    • 请尝试使用 www-data 所以
    • 使用www-data so 代替nginx:nginx ?
    • 我试过了,但我仍然收到 405 错误 :(。www-data 是什么?我的 /var/www 目录没有 data 目录?
    • www-data 通常是运行您的 PHP 脚本的用户。所以它必须能够读取和执行文件。我认为您必须找出哪个用户正在为您的网络服务器运行并为它服务
    猜你喜欢
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    • 2015-09-08
    • 2017-06-29
    • 1970-01-01
    • 2017-11-13
    • 2021-12-20
    • 2014-09-01
    相关资源
    最近更新 更多