html 如何使用Nginx提交一个没有扩展名的文件?

ia2d9nvy  于 9个月前  发布在  Nginx
关注(0)|答案(1)|浏览(157)

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

wixjitnu

wixjitnu1#

最后我想明白了:

  • index /home;需要一个斜杠
  • try_files需要$uri.html不知道为什么,但没有它将无法工作。
#
#   Server Configuration
#
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;

    }
}

字符串

相关问题