我的所有静态HTML文件都没有扩展名,这意味着它们不是index.html
,它们只是index
。如何告诉Nginx访问它们并将它们作为HTML文件提供?我有以下配置。
server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
include snippets/snakeoil.conf;
root /home/davidgatti/Documents/example.com;
index home
server_name example.loc;
location / {
default_type text/html;
try_files $uri $uri $uri/ =404;
}
}
现在Nginx送回一个404
。
最终我弄清楚了:
index /home;
需要一个斜线try_files
需要$uri.html
不确定为什么,但没有它将无法工作。
#
服务器配置
#server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
#
# Use the a default SSL for development.
#
include snippets/snakeoil.conf;
#
# Tell which folder to server.
#
root /home/davidgatti/Documents/Retireryte/YOUR_SITE_NAME/_output;
#
# Set the default file.
#
index /home;
#
# Tell Nginx which url is this configuration for.
#
server_name login.example.loc;
#
# Default configuration.
#
location / {
#
# Since we deliver files with no extension, we need to tell
# Nginx what those files are.
#
default_type text/html;
#
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#
try_files $uri $uri.html $uri/ =404;
}
}