2016-04-12 149 views
3

我想配置nginx到服務器的HTML文件來查看而不是下載。如何配置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,我的瀏覽器嘗試提供下載的文件,而不是觀看它。謝謝你的幫助。

回答

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

我覺得上面的方法是有效的,也許還有其他的答案。

0
just set new "types" for location: 

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

location =/login {root/home/vagrant/own/base/assets; 類型{application/octet-stream html; } alias /home/vagrant/own/base/assets/login.html; } 是否這樣? – zimmer

+0

如果答案是正確的,請將其標記爲答案,然後帖子的狀態將被調整爲'已回答' –

+0

這對我來說不起作用。它只需下載login.html @Shayan Ghosh – zimmer

相關問題