我想实现这样的目标:
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/