问题描述
如何为域名设置 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.
我尝试了不同的方法,例如:
I've tried different things like:
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 设置为根文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!