新安装的nginx导致浏览器下载index.html而不是打开它

当我在Chrome, http://localhost:90查看这个文件时,该文件被下载而不是显示在Chrome中。

这个问题在SO上被问了很多次,但是关于索引。 PHP文件。 我的问题是一个简单的HTML文件,而不是一个PHP文件。 那还没有被问到。 我希望解决scheme是相似的,但我一直没能弄明白。

这是我的example.com.conf:

 server { server_name localhost; listen 90; root /var/www/example.com/html index index.html location / { try_files $uri $uri/ =404; } } 

我的index.html文件只包含两个单词,没有标记

 Hello World 

我认为这是mime.types。 mime.types文件中有html的条目。 这是一个新鲜的nginx安装。

nginx -t报告“testing成功”

确保mime.types具有文本/ html文件的扩展名“html”。 这篇文章详细介绍了如何强制nginx提供html下载而不是显示,所以也许反过来。

删除这个:

位置/ {try_files $ uri $ uri / = 404; }

我认为这是问题,你需要把你的位置/第一,然后你也可以添加它之前(坏英语,我尝试改善)

或者试试这个vHost:

 server { listen 90; server_name localhost; autoindex on; location / { root /var/www/example.com/html; index index.html; } }