NGINX:如何返回内联 html?

标签 nginx

我想实现这样的目标:

server {
    listen 80;
    location / {
        return 200 <html><body>Hello World</body></html>
    }
}

即,任何请求都应返回内联 html。这可以用 NGINX 实现吗?

编辑:

我试过这个:
server {
    listen 80;
    location / {
        return 200 '<html><body>Hello World</body></html>'
    }
}

但是在浏览器中测试并没有呈现 html,而是浏览器试图下载一个包含 html 的文件,这不是我想要的行为。

最佳答案

你有没有尝试过?

server {
    listen 80;

    location / {
        add_header Content-Type text/html;

        return 200 '<html><body>Hello World</body></html>';
    }
}

关于NGINX:如何返回内联 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57894195/

相关文章:

python - 通过 Gunicorn 上传 Flask 和 NGINX 流式文件

Nginx proxy_pass 到 https

javascript - 生产规模太大

nginx - 对具有 HHVM 的站点使用单独的池

python - Django 不断从 http ://localhost/to http://127. 0.0.1:8080/更改 URL

django - 我不知道为什么 Nginx 服务器不工作

nginx - 出现 404 时重定向到另一个站点

python - Django/子目录/admin/重定向到/admin/login/?next=/admin/

ssl - Nginx HTTPS 连接被拒绝

http - Nginx 在不提供文件的情况下返回 200