Nginx下载文件,不显示内容

Moh*_*mba 6 php nginx 14.04

在我的网站上,我有一些验证文件,我需要将其放入没有扩展名的文档根目录中,只有“验证文件”,

但是当我尝试从浏览器打开它时,它会下载而不是打开,所有其他扩展名为 (.txt) 的文件都可以正常打开,

我的 nginx (1.12) 配置:

server {
listen 80;
listen 443 ssl;

root /var/www/website;
error_log /var/log/nginx/website-error.log;
access_log /var/log/nginx/website-access.log;

index index.php index.html index.htm index.nginx-debian.html;

server_name website.com;
ssl_certificate /etc/ssl/website/nginx_bundle.crt;
ssl_certificate_key /etc/ssl/website/website.key;

location / {
    index index.php index.html;
    try_files $uri $uri/ =404 /index.php?q=$uri&$args;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
    root /var/www/website;

    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/website/$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny all;
}
Run Code Online (Sandbox Code Playgroud)

小智 7

nginx从扩展中确定内容类型。如果文件没有扩展名,它将使用default_type.

您可以通过在其自己的location块中处理它来显式设置此文件的内容类型:

location = /validation-file {
    types {}
    default_type text/html;
}
Run Code Online (Sandbox Code Playgroud)

设置default_type为文件包含的任何内容,例如text/htmlortext/plain等。

有关更多信息,请参阅此文档