如何配置nginx来提供HTML文件以供查看而不是下载?

时间:2016-04-12 11:53:46

标签: nginx

我想将nginx配置为服务器HTML文件以供查看而不是下载。

server {
    listen       5000;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    #location / {
    #    root   html;
    #    index  index.html index.htm;
    #}

    location = / {
        root /home/vagrant/own/base/assets;
        index index.html;
    }

    location = /login {
    #    root /home/vagrant/own/base/assets;
          alias /home/vagrant/own/base/assets/login.html;
    }

    location /index.html {
        root /home/vagrant/own/base/assets;
    }
}

这是我的conf文件,当我浏览/login时,我的浏览器会尝试提供下载文件而不是查看文件。谢谢你的帮助。

2 个答案:

答案 0 :(得分:7)

    location = /login {
        default_type "text/html";
        alias /home/vagrant/own/base/assets/login.html;
    }

我认为上述方法很有效,可能还有其他答案。

答案 1 :(得分:0)

just set new "types" for location:

location /saveonly/ {
     types  { application/octet-stream  html; }
     ...
}