如何使用Nginx提供没有扩展名的文件?

问题描述 投票:0回答:1

我的所有静态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

html nginx configuration
1个回答
0
投票

最终我弄清楚了:

  • 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; } }
© www.soinside.com 2019 - 2024. All rights reserved.