【问题标题】:Can't modify nginx index.html file无法修改 nginx index.html 文件
【发布时间】:2016-06-21 16:20:08
【问题描述】:

如果我连接www.my-hsot.com,那么总是输出“你好!”文字..

但是我的 index.html 文件内容什么都没有。我只想要空白页.. 如何修改默认索引文件?

这是我的默认配置:

server {
    listen 80;

    root /home/me;
    index index.php index.html index.htm;

    server_name www.my-hsot.com;

    location / {
        try_files $uri $uri/ /index.php?$request_uri;
    }

   location /.well-known {
        root /home/me/well-known;
   }


    location ~ \.php$ {
        include                  fastcgi_params;
        fastcgi_keep_conn on;
        fastcgi_index            index.php;
        fastcgi_split_path_info  ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    }
}

这是 nginx 默认索引文件(路径:/usr/share/nginx/html/index.html)是:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

【问题讨论】:

    标签: nginx


    【解决方案1】:

    你已经设置了

    root /home/me;
    index index.php index.html index.htm;
    ...
    location / {
       try_files $uri $uri/ /index.php?$request_uri;
    }
    

    所以,当访问 / 时,nginx 会首先查找传递给 fcgi 处理程序的 index.php。我想这就是“你好!”的地方。来自:你的 index.php。

    如果没有index.php,则会查找index.html,但是在文档根目录/home/me中。

    要在 / 上获得空白页,您可以使用类似

    location ~ "^[/]?$" {
      return 200;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-28
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多