'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.
Solution 1:[1]
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.
Solution 2:[2]
just set new "types" for location:
location /saveonly/ {
types { application/octet-stream html; }
...
}
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | zimmer |
Solution 2 | Shayan Ghosh |
Solution 3 | padraig j houlahan |