找不到托管在 AWS S3 上的静态网站错误 404

时间:2021-02-20 03:50:45

标签: amazon-web-services amazon-s3

我在 Rapidweaver (nrgies.com) 中创建了一个静态网站,并设法将它托管在 AWS S3 上,但我的“联系方式”页面出现以下错误

<块引用>

404 未找到

代码:NoSuchKey

消息:指定的键不存在。

密钥:nrgies.s3.eu-west-2.amazonaws.com/error.html 请求 ID:3C9DE5ABDA5C6F94 主机 ID:KWAoZQx1/Iozh3kl+OpzfZaR0DMuVByHKVp1X/sJyM8wASwCEiFIJ5mC4NzzRrPlMjdiCErYkfc=

我已授予对存储桶的公共访问权限,因为它可以与其他页面一起使用,但由于某种原因它无法解析联系表单

在我的 contact_form 文件夹中,我有一个 index.php 和一个带有 mailer.php 的文件夹

index.php 如下 - 有人可以用简单的语言指导我在这里缺少什么吗?

index.php:

<?php
    // Start session.
    session_start();
    
    // Set a key, checked in mailer, prevents against spammers trying to hijack the mailer.
    $security_token = $_SESSION['security_token'] = uniqid(rand());
    
    if ( ! isset($_SESSION['formMessage'])) {
        $_SESSION['formMessage'] = 'Please complete the form and a member of our team will contact you.';   
    }
    
    if ( ! isset($_SESSION['formFooter'])) {
        $_SESSION['formFooter'] = ' ';
    }
    
    if ( ! isset($_SESSION['form'])) {
        $_SESSION['form'] = array();
    }
    
    function check($field, $type = '', $value = '') {
        $string = "";
        if (isset($_SESSION['form'][$field])) {
            switch($type) {
                case 'checkbox':
                    $string = 'checked="checked"';
                    break;
                case 'radio':
                    if($_SESSION['form'][$field] === $value) {
                        $string = 'checked="checked"';
                    }
                    break;
                case 'select':
                    if($_SESSION['form'][$field] === $value) {
                        $string = 'selected="selected"';
                    }
                    break;
                default:
                    $string = $_SESSION['form'][$field];
            }
        }
        return $string;
    }
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>

    <meta charset="utf-8" /> 
<link rel="preconnect" href="https://fonts.gstatic.com"> 
<link href="https://fonts.googleapis.com/css2?
family=Archivo:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="description" content="Please complete our enquiry form, email or call us on:
e: info@nrgies.com 
m: 07956 500315" />
        <meta name="robots" content="index, follow" />
        <link rel="apple-touch-icon" sizes="167x167" href="http://nrgies..com/resources/medium.png" />
<link rel="apple-touch-icon" sizes="180x180" href="http://nrgies..com/resources/large.png" />
<link rel="apple-touch-icon" sizes="152x152" href="http://nrgies..com/resources/small.png" />
<link rel="mask-icon" href="http://nrgies..com/resources/NRGies_Blue%20Logo.png" color="rgba(0,0,255,1.00)" /><link rel="icon" type="image/png" href="http://nrgies..com/resources/favicon_medium.png" sizes="32x32" />
<link rel="icon" type="image/png" href="http://nrgies..com/resources/favicon_small.png" sizes="16x16" />
<link rel="icon" type="image/png" href="http://nrgies..com/resources/NRGies_Blue%20Logo.png" sizes="64x64" />

    <meta name="twitter:card" content="summary">
    <meta name="twitter:title" content="NRGies Contact">
    <meta name="twitter:description" content="Please complete our enquiry form, email or call us on:
e: info@nrgies.com 
m: 07956 500315">
    <meta name="twitter:image" content="http://nrgies.ddns.net:8085/resources/Banner.jpg">
    <meta name="twitter:url" content="http://nrgies.ddns.net:8085/contact_form/index.php">
    <meta property="og:type" content="website">
    <meta property="og:site_name" content="NRGies">
    <meta property="og:title" content="NRGies Contact">
    <meta property="og:description" content="Please complete our enquiry form, email or call us on:
e: info@nrgies.com 
m: 07956 500315">
    <meta property="og:image" content="http://nrgies.ddns.net:8085/resources/Banner.jpg">
    <meta property="og:url" content="http://nrgies.ddns.net:8085/contact_form/index.php"> 

    <!-- Meta tags -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />

    <title>NRGies Contact</title>
    <link rel="stylesheet" type="text/css" media="all" href="../rw_common/themes/Mountains/consolidated.css?rwcache=635471980" />
        
        
</head>

<!-- This page was created with RapidWeaver from Realmac Software. http://www.realmacsoftware.com -->

<body>
    <div class="hero" id="hero">
        <nav class="navbar navbar-expand-lg pt-3">
            <div class="container">
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false"
                    aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav mr-auto"><li class="nav-item"><a href="../" rel="" class="nav-link">Home</a></li><li class="nav-item has-dropdown"><a href="../page-3/" rel="" class="nav-link dropdown-toggle" data-toggle="dropdown">Services</a><ul class="navbar-nav mr-auto"><li class="nav-item"><a href="../page-3/page-2/" rel="" class="nav-link">IT Services</a></li><li class="nav-item"><a href="../page-3/page-6/" rel="" class="nav-link">Home Automation</a></li><li class="nav-item"><a href="../page-3/page/" rel="" class="nav-link">Energy Management</a></li></ul></li><li class="nav-item"><a href="../page-4/" rel="" class="nav-link">Fees</a></li><li class="nav-item active"><a href="./" rel="" class="nav-link">Contact</a></li></ul>
                </div>
            </div>
        </nav>

        <div class="hero-content" id="hero">
            <div class="container">
                <div class="row">
                    <div class="col">
                        <h1 class="hero-title display-1" data-aos="fade-right" data-aos-delay="300" data-aos-duration="500">Contact</h1>
                        <h2 class="hero-slogan font-italic display-4" data-aos="fade-right" data-aos-delay="350" data-aos-duration="500"></h2>
                    </div>
                </div>
            </div>
        </div>

        <div class="hero-background"></div>
    </div>


    <main class="content">
        <div class="container">
            <div class="row intro justify-content-between">
                <div class="col-sm-8 intro-col" data-aos="fade-right" data-aos-delay="300" data-aos-duration="500">
                    
<div class="message-text"><?php echo $_SESSION['formMessage']; unset($_SESSION['formMessage']); ?></div><br />

<form class="rw-contact-form" action="./files/mailer.php" method="post" enctype="multipart/form-data">
     <div>
        <label>Your Name</label> *<br />
        <input class="form-input-field" type="text" value="<?php echo check('element0'); ?>" name="form[element0]" size="40"/><br /><br />

        <label>Your Email</label> *<br />
        <input class="form-input-field" type="text" value="<?php echo check('element1'); ?>" name="form[element1]" size="40"/><br /><br />

        <label>Subject</label> *<br />
        <input class="form-input-field" type="text" value="<?php echo check('element2'); ?>" name="form[element2]" size="40"/><br /><br />

        <label>Message</label> *<br />
        <textarea class="form-input-field" name="form[element3]" rows="8" cols="38"><?php echo check('element3'); ?></textarea><br /><br />

        <div style="display: none;">
            <label>Spam Protection: Please don't fill this in:</label>
            <textarea name="comment" rows="1" cols="1"></textarea>
        </div>
        <input type="hidden" name="form_token" value="<?php echo $security_token; ?>" />
        <input class="form-input-button" type="reset" name="resetButton" value="Reset" />
        <input class="form-input-button" type="submit" name="submitButton" value="Submit" />
    </div>
</form>

<br />
<div class="form-footer"><?php echo $_SESSION['formFooter']; unset($_SESSION['formFooter']); ?></div><br />

<?php unset($_SESSION['form']); ?>

                </div>
                <div class="sidebar col-sm-4 order-md-8" data-aos="fade-up">
                    <div class="logo" data-aos-delay="450" data-aos-duration="500">
                        <img src="../rw_common/images/NRGies Con_07E6FF Logo.png" width="169" height="76" alt="NRGies"/>
                    </div>

                    <div class="mt-5">
                        <h3 class="sidebar-title">
                            Contact us
                        </h3>
                        Please complete our enquiry form, email or call us on:<br />e: info@nrgies.com <br />m: 07956 500315<br />a: Abbey Court, Abbey Rd, London, NW8 0AU
                        
                    </div>
                </div>
            </div>
        </div>

        <div class="footer">
            <div class="container">
                <div class="row">
                    <div class="col" data-aos="fade-right" data-aos-delay="0" data-aos-duration="500">
                        <div class="footer-content text-center">
                            &copy; Copyright 2010 NRGies Consulting Ltd. All Rights Reserved. <a href="#" id="rw_email_contact">             Contact Me</a><script type="text/javascript">var _rwObsfuscatedHref0 = "mai";var _rwObsfuscatedHref1 = "lto";var _rwObsfuscatedHref2 = ":in";var _rwObsfuscatedHref3 = "fo@";var _rwObsfuscatedHref4 = "nrg";var _rwObsfuscatedHref5 = "ies";var _rwObsfuscatedHref6 = ".co";var _rwObsfuscatedHref7 = "m";var _rwObsfuscatedHref = _rwObsfuscatedHref0+_rwObsfuscatedHref1+_rwObsfuscatedHref2+_rwObsfuscatedHref3+_rwObsfuscatedHref4+_rwObsfuscatedHref5+_rwObsfuscatedHref6+_rwObsfuscatedHref7; document.getElementById("rw_email_contact").href = _rwObsfuscatedHref;</script>
                        </div>

                        <ul class="navbar-nav mr-auto"><li class="nav-item"><a href="../" rel="" class="nav-link">Home</a></li><li class="nav-item has-dropdown"><a href="../page-3/" rel="" class="nav-link dropdown-toggle" data-toggle="dropdown">Services</a></li><li class="nav-item"><a href="../page-4/" rel="" class="nav-link">Fees</a></li><li class="nav-item active"><a href="./" rel="" class="nav-link">Contact</a></li></ul>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <script type="text/javascript" src="../rw_common/themes/Mountains/js/main.js?rwcache=635471980"></script>
</body>

</html>

1 个答案:

答案 0 :(得分:0)

静态网站意味着它们没有可以执行的服务器端代码。 PHP 是一种必须在网络服务器上执行的语言,@hephalump 在注释中引用 this question 指出该语言不受支持。

这意味着您不能使用 PHP 为 S3 中的静态网站创建联系表单,因为它需要服务器端交互。

您向我们展示的错误消息来自不同的来源。

当您在 S3 中设置静态网站托管时,它允许您设置一个网站索引文档和一个错误文档。如果您访问域,则索引将是默认页面,如果用户导航到不存在的键或其他错误,则会显示错误文档。

您会看到错误消息,因为存储桶中不存在 error.html(您配置的错误文档)。大概 S3 注意到您试图做一些它不能做的事情,因此将您重定向到不存在的错误文档。