gpt4 book ai didi

http - nginx httpssubmodule 替换 html 内容

转载 作者:可可西里 更新时间:2023-11-01 16:25:13 26 4
gpt4 key购买 nike

我刚刚遇到了 nginx https 子模块。我认为这可能会帮助我做到这一点。

我有静态的 HTML 页面,我想在输出 html 中使用 uri 部分。例如我的静态网址是 http://static.mydomain.com/pic1234.html所以在页面中我想显示单词“pic1234”。我不能使用 javascript,因为我想为静态页面生成 HTML 元数据。

这能做到吗?如果是这样怎么办?我找不到任何例子。我只找到了这个 http://wiki.nginx.org/NginxHttpSubModule

请注意,我在服务于 nginx 服务器的静态文件上没有 cgi 或程序。

最佳答案

我创建了一个简单的示例。使用此配置,nginx 将 html 页面中的 __name__ 标记替换为请求的 html 的文件名(在本例中为“pic1234”):

nginx 配置:

server {
listen 80;
server_name localhost;

root D:/Development/public;
sub_filter_once off;

location / {
if ($uri ~* /(\w+)\.html$) {
set $filename "$1";
}
sub_filter "__name__" $filename;
try_files $uri $uri/ ;
}
}

D:/Development/public/pic1234.html:

<html>
<head>
<title>__name__</title>
</head>
<body>
<h1>Contents of __name__:</h1>
</body>
</html>

您可以找到要点 here

关于http - nginx httpssubmodule 替换 html 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11087633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com