You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Nginx配置中使/en/health路由的health.html网页正常展示而非被下载

Fixing Nginx Health Page Downloading Instead of Displaying

Let's walk through the fixes to get your /en/health page showing up correctly in the browser instead of downloading.

1. Fix the HTML Syntax Error First

Your health.html has a typo that will break rendering even if the server setup is correct:

<div<h1>I am a healthy page</h1></div>

Change that to properly close the opening <div> tag:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Sample site</title>
</head>
<body>
    <div><h1>I am a healthy page</h1></div>
</body>
</html>

2. Ensure Nginx Recognizes HTML MIME Types

If your Nginx config doesn't include the mime.types file, it won't send the correct Content-Type: text/html header for .html files—this is the most common reason browsers download HTML instead of displaying it.

Add this line at the top of your Nginx configuration (outside the server block):

include /etc/nginx/mime.types;

The path might vary slightly depending on your Docker image, but /etc/nginx/mime.types is standard for official Nginx images.

3. Adjust the /en/health Location Configuration

Your current alias setup can be simplified to avoid path confusion. Here are two solid options:

Option A: Point Directly to the Health File

If you only need /en/health to serve the single health.html file, use this cleaner configuration:

location = /en/health {
    root /usr/share/nginx/html;
    try_files /en/health/health.html =404;
}

The = sign makes this an exact match, which is more efficient and avoids unintended path matches.

Option B: Fix the Alias for Directory Access

If you want to allow accessing /en/health/ (with trailing slash) as well, adjust the alias to match the location structure properly:

location /en/health/ {
    alias /usr/share/nginx/html/en/health/;
    index health.html;
}

Notice the trailing slash on both the location and alias—this ensures Nginx maps the paths correctly without adding extra segments. If you want to support both /en/health and /en/health/, add a redirect:

location = /en/health {
    return 301 /en/health/;
}

location /en/health/ {
    alias /usr/share/nginx/html/en/health/;
    index health.html;
}

4. Test and Reload Nginx

After making these changes, test your config for syntax errors:

nginx -t

If it passes, reload Nginx to apply the changes:

nginx -s reload

That should resolve the downloading issue and get your health page displaying as expected.

内容的提问来源于stack exchange,提问作者RyanP13

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 20:57:50