NGINX 不显示我的 index.html - 保持默认

NGINX 不显示我的 index.html - 保持默认
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/apexnetwork.org/public_html/;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name   *.apexnetwork.org;
    server_name   .apexnetwork.org;

    location / {
            try_files $uri $uri/ /index.html;
    } 
}

这是我的索引:

    <!DOCTYPE html>
<html lang="en">
   <!-- Metadata, Stylesheet, Title -->
   <head>
      <title>Home | Apex Network</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <meta name="description" content="Apex Network">
      <meta name="author" content="Jerred Shepherd">
      <link rel="shortcut icon" href="img/favicon.ico">
      <link href="css/bootstrap.min.css" rel="stylesheet">
      <link href="css/font-awesome.min.css" rel="stylesheet">
      <link href="css/custom.css" rel="stylesheet">
   </head>
   <!-- Navbar Start -->
   <body>
      <div class="navbar-wrapper">
         <div class="container">
            <div class="navbar navbar-default navbar-fixed navbar-fixed-top" role="navigation">
               <div class="container">
                  <div class="navbar-header">
                     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                     <span class="sr-only">Toggle navigation</span>
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                     </button>
                     <a class="navbar-brand accent" href="">Apex Network</a>
                  </div>
                  <div class="navbar-collapse collapse">
                     <ul class="nav navbar-nav">
                        <li class="active"><a href="index.html"><i class="fa fa-home"></i> Home</a>
                        </li>
                        <li><a href="play.php"><i class="fa fa-gamepad"></i> Play</a>
                        </li>
                        <li><a href="forum"><i class="fa fa-comments-o"></i> Forum</a>
                        </li>
                        <li><a href="shop.html"><i class="fa fa-shopping-cart"></i> Shop</a>
                        </li>
                        <li><a href="stats"><i class="fa fa-bar-chart-o"></i> Stats</a>
                        </li>
                     </ul>
                     <ul class="nav navbar-nav navbar-right">
                        <li class="dropdown">
                           <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> Account <b class="caret"></b></a>
                           <ul class="dropdown-menu">
                              <li><a href="#">Login</a>
                              </li>
                              <li><a href="#">Register</a>
                              </li>
                           </ul>
                        </li>
                        <a href="play.php" class="btn btn-info navbar-btn navbar-right hidden-sm hidden-xs">IP:
                        ApexNetwork.org</a>
                     </ul>
                  </div>
               </div>
            </div>
         </div>
      </div>
      <!-- Main Image -->
      <div class="bg-container">
         <img alt="Background Image" class="random bgimg" height="1920" width="640">
      </div>
      <div class="up2 text-center">
         <div class="col-md-6 col-md-offset-3">
            <h1 class="caption">Apex Network</h1>
            <p class="captionbody">Welcome to the ApexNetwork. Prison and factions</p>
            <p><a class="btn btn-lg btn-primary" href="/play.html" role="button">Play Now &#187;</a>
            </p>
         </div>
      </div>
      <br>
      <br>
      <!-- "Marketing" Area -->
      <div class="container marketing up">
         <div class="row">
            <div class="col-lg-4">
               <img class="img-circle glow" src="img/marketing/1.jpg" height="150" width="150" alt="Marketing Image 1">
               <h2>Voting!</h2>
               <p>Click here to go to the voting list!</p>
               <p> <a href="/vote.html">
                  <button class="btn btn-default" href="#" role="button"></i>Vote &raquo;</button>
                  </a>
               </p>
            </div>
            <div class="col-lg-4">
               <img class="img-circle glow" src="img/marketing/1.jpg" height="150" width="150" alt="Marketing Image 2">
               <h2>Donate!</h2>
               <p>Click here to go to the Buycraft webstore!!</p>
               <p> <a href="http://apexnetwork.buycraft.net/">
                  <button class="btn btn-default" href="#" role="button"></i>Buy &raquo;</button>
                  </a>
               </p>
            </div>
            <div class="col-lg-4">
               <img class="img-circle glow" src="img/marketing/3.jpg" height="150" width="150" alt="Marketing Image 3">
               <h2>Bans.</h2>
               <p>This is where you go, to see your ban reason.
               </p>
               <p> <a href="/bans">
                  <button class="btn btn-default" href="#" role="button"></i>Details &raquo;</button>
                  </a>
               </p>
            </div>
         </div>
      </div>
      <!-- Footer -->
      <div id="footer">
         <div class="container hidden-sm hidden-xs">
            <hr>
            <ul class='nav nav-pills'>
               <li class='pull-left'><a href="http://shepherdjerred.com/">Design by Jerred Shepherd
                  </a>
               </li>
               <li class="pull-right">
                  <a href="terms.html">Terms</a>
               </li>
               <li class="pull-right">
                  <a href="contact.html">Contact</a>
               </li>
               <li class="pull-right">
                  <a href="bans">Bans</a>
               </li>
               <li class="pull-right">
                  <a href="staff.html">Staff</a>
               </li>
            </ul>
            <br>
         </div>
      </div>
      <script src="js/jquery.min.js" type="text/javascript"></script>
      <script src="js/bootstrap.min.js" type="text/javascript"></script>
      <script>
         function getRandomInt(min, max) {
             return Math.floor(Math.random() * (max - min + 1)) + min;
         }

         var imagePath = "img/bg/";

         function displayLogo() {
             var filename = "bg" + getRandomInt(1, 4).toString() + ".jpg";

             $(".random").attr({
                 "src": imagePath + filename,
             });
         }

         $(document).ready(function () {
             displayLogo();
         });
      </script>
   </body>
</html>

这是我的可用网站配置。但每次我访问我的网站时,它都显示默认的 nginx 索引。

答案1

尝试对 server_name 执行此操作:

server_name   *.apexnetwork.org apexnetwork.org;

答案2

这是我的设置。我认为您的位置配置不正确。

location = / { index index.html =404; }
    location / {
        try_files $uri.html $uri/index.html $uri =404;
    }

答案3

您获取的是默认的 NGINX 页面,因为您的 server_name 告诉 NGINX 您的配置目录不是用于localhost,因此 NGINX 使用默认安装目录来提供页面localhost

测试以下内容:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/apexnetwork.org/public_html/;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name   *.apexnetwork.org localhost;
    #Alternate for default server would be to leave server_name out altogether to make the configuration a catch-all configuration

    #server_name   .apexnetwork.org;

    location / {
            try_files $uri $uri/ /index.html;
    } 
}

页面内容其实并不重要。我的建议是从基础开始。try_files在系统正常运行之前,请避免使用更复杂的命令。

在这种情况下,虽然该root命令在服务器域中确实正确运行,但所有文档通常都提供了rootlocation域的示例。

您看到的是 NGINX 页面,这说明问题不在于您从浏览器访问服务器。但是,我注意到您有一条注释表明需要访问http://localhost,但您的配置文件还不允许这样做。我想象您正在尝试使用 进行连接http://localhost,而 NGINX 正在查看您的配置文件并自言自语:“此配置仅适用于 *.apexnetwork.org,不适用于 localhost。”

http://nginx.org/en/docs/beginners_guide.html在标题为“提供静态内容”的部分中,他们讨论了如何设置 localhost。您会在示例中注意到,当未提供服务器名称时,配置将充当一个 catchall 并将处理localhost请求,因此,除非您正在运行一个虚拟服务器,该服务器为维护在单独目录位置的多个域提供服务,否则您应该遵循初学者指南中的示例并省略 server_name 命令。这会将您的配置文件变成一个 catch-all,无论 URL 中请求的域是什么,它都会响应端口 80 上的所有请求。

但是,如果您尝试为 *.apexnetwork.org 以及一个或多个其他域提供服务,并且希望 apexnetwork.org 作为本地主机,那么您必须使用 server_name 命令,该命令如下:

server {
     listen 80 default_server;
     server_name *.apexnetwork.org localhost;
     #continue here with remainder of settings
}

这会告诉 NGINX,server块内的所有内容都属于域 *.apexnetwork.org(www.apexnetwork.org、mail.apexnetwork.org、vpn.apexnetwork.org 等)下的所有 URL,以及与单词“localhost”完全匹配的所有域。

有关 server_name 使用的更多详细信息,请参阅此链接:服务器名称文档

相关内容