Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure nginx to serve HTML files for viewing instead of downloading?

Tags:

nginx

I want to configure nginx to server HTML files for viewing instead of downloading.

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;
    }
}

This is my conf file, when I browse to /login, my browser tries to offer the file for download instead of viewing it. Thanks for your help.

like image 236
zimmer Avatar asked Apr 12 '16 11:04

zimmer


1 Answers

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

I think the approach above is effective, there maybe other answers.

like image 127
zimmer Avatar answered Nov 08 '22 13:11

zimmer