【问题标题】:How to remove trailing slash after file extension using Nginx?如何使用 Nginx 删除文件扩展名后的斜杠?
【发布时间】:2019-07-04 15:25:13
【问题描述】:

我在example.comwww.example.com 有一个Ghost 站点(在内部,它在端口2368 上运行)。同时,我有一个名为form.pdf 的文件,我想让它在以下位置可用(在浏览器中查看,而不是要求用户下载):

  • example.com/form.pdf
  • www.example.com/form.pdf

使用下面的配置,它只有在 .pdf 扩展名之后包含斜杠时才有效,如下所示:

  • example.com/form.pdf/
  • www.example.com/form.pdf/

PDF文件路径:

/var/www/ghost/pdfs/form.pdf

配置文件路径:

/etc/nginx/sites-available/ghost

配置文件:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    server_name 123.45.678.901 localhost example.com *.example.com;

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 100M;

    location "/form.pdf" {
        alias /var/www/ghost/pdfs;
        index form.pdf;
    }

    location / {
        proxy_pass http://localhost:2368;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }
}

当我删除 .pdf 扩展名后的斜杠时,出现 404 错误。

问题:

如何正确配置 Nginx 使其在末尾没有斜杠的情况下工作?

【问题讨论】:

    标签: nginx ghost-blog


    【解决方案1】:

    我找到了答案。这个对我有用:

    location = /form.pdf {
            root /var/www/ghost/pdfs;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多