本文介绍了如何在Nginx中将index.html设置为根文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为域名设置index.html,例如 https://www.example.com/-引导用户访问根目录中的index.html.

How to set index.html for the domain name e.g. https://www.example.com/ - leads user to index.html in root directory.

我尝试过类似的事情:

server {
    # some configs

    location = / {
            index index.html;
            fastcgi_index index.html;
    }
or
    location / {
            index index.html;
            fastcgi_index index.html;
    }

}

没有任何帮助.

还有一些其他带有location关键字的配置,尽管我也对它们进行了评论.

There are some other configs with location keyword, though I'd commented them either.

server {子句中的其他位置"配置:

Other "location" configs in the server { clause:

location ~ .*(css|htc|js|bmp|jp?g|gif|ico|cur|png|swf|htm?|html)$ {
        access_log off;
        root $www_root;
}

location ~ \.php$
{
        include                         /etc/nginx/fastcgi_params;
        index                           index.html;
        fastcgi_index                   index.html;
        fastcgi_param SCRIPT_FILENAME   $www_root$fastcgi_script_name;
        fastcgi_param QUERY_STRING      $query_string;
        fastcgi_param PATH_INFO         $fastcgi_path_info;
        fastcgi_pass                    127.0.0.1:9000;
        # Директива определяет что ответы FastCGI-сервера с кодом больше или равные 400
        # перенаправлять на обработку nginx'у с помощью директивы error_page
        fastcgi_intercept_errors        on;
        break;
}

location ~ /\.ht {
    deny all;
}

所有评论和评论都没有,但没有任何帮助.

All them were commented and uncommented, but nothing helped.

PS版本是在/etc/nginx/sites-enabled/domainname.com文件中制作的.

PS Editions were made in /etc/nginx/sites-enabled/domainname.com file.

推荐答案

答案是将根目录放置在location指令中:

The answer is to place the root dir to the location directives:

root   /srv/www/ducklington.org/public_html;

这篇关于如何在Nginx中将index.html设置为根文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:12