zimmer
zimmer

Reputation: 1197

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

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.

Upvotes: 8

Views: 9682

Answers (3)

padraig j houlahan
padraig j houlahan

Reputation: 1

Just in case someone can benefit from my mistake - I had deleted the default server from the nginx sites-enabled area and no matter what I did, the browser would download the index.html file instead of opening it. It made no difference what I did with mime types in the server block files. After finding a replacement copy online, and installing it in the sites-enabled directory, and restarting nginx, the problem went away.

Upvotes: 0

zimmer
zimmer

Reputation: 1197

    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.

Upvotes: 8

Shayan Ghosh
Shayan Ghosh

Reputation: 892

just set new "types" for location:

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

Upvotes: 0

Related Questions