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

标签 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 时,我的浏览器会尝试提供文件以供下载,而不是查看它。谢谢你的帮助。

最佳答案

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

我认为上述方法是有效的,也许还有其他答案。

关于nginx - 如何配置 nginx 以提供 HTML 文件以供查看而不是下载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36572533/

相关文章:

perl - 如何在同一个 nginx 服务器上运行多个 perl Dancer2 应用程序

nginx - 流浪的: config. vm.provision不允许我将文件复制到etc/nginx/conf.d吗?

python - 使用 uWSGI 在 nginx 下部署的 Flask 在哪里获取我的 Python 打印件?

Nginx 重写语法

django - nginx + Gunicorn 抛出截断的响应正文

ruby-on-rails - Capistrano + Thin + nginx 不允许用户使用 sudo howto?

nginx - 为 nginx 和乘客配置 CORS

node.js - nginx x-accel-redirect 与 304 响应的 etag 比较

grails - Nginx 允许页面上出现不安全的内容

docker - 为什么我得到 Host is unreachable from React code 而不是浏览器?