Nginx无法托管HTML文件

时间:2017-09-28 04:37:08

标签: html nginx webserver

当我尝试托管HTML或文本文件时出现以下错误:

  

2017/09/27 21:30:06 [emerg] 4652#13640:意外的文件结束,   期待“;”或C:/nginx/html/reports/Summary.html中的“}”:1068

看起来它无法识别文件的类型(我猜) server_name字段似乎也没有按预期工作。

我错过了什么吗?

这是文件头的外观:

<!DOCTYPE html>
<html>
<head><title>Content Summary</title>

<meta charset="utf-8" http-equiv="Content-Type" content="text/html">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>

这是我的nginx conf:

user www-data;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include C:/nginx/conf/mime.types;
    default_type  application/octet-stream;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 600;
    types_hash_max_size 2048;

    proxy_read_timeout 300;
    proxy_connect_timeout 300;
    server {
        listen       89;
        server_name  reports.devops.com;

        location / {
            include C:/nginx/html/reports/Summary.html;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

包含是用于包含nginx配置。因此,您需要将配置文件更改为

user www-data;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include C:/nginx/conf/mime.types;
    default_type  application/octet-stream;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 600;
    types_hash_max_size 2048;

    proxy_read_timeout 300;
    proxy_connect_timeout 300;
    server {
        listen       89;
        server_name  reports.devops.com;

        location / {
            root C:/nginx/html/reports/;
            index index.html Summary.html;
            try_files $uri $uri/;
        }
    }
}

root C:/nginx/html/reports/;指令将告诉nginx您希望从此目录提供文件。 index index.html Summary.html;指令会告诉它搜索index.html等文件,Summary.html没有指定文件。 try_files $uri $uri/;将告诉nginx将url检查为文件或文件夹。