Netflix优惠码论坛

完整版: Onion 网站宣传:位置服务
你目前正在浏览的是简化版. 请点击这里浏览完整版
Onion-Location 是向用户宣传洋葱网站的一种简单方法。您可以配置 Web 服务器以显示 Onion-Location 标头或<meta>在网站中添加 HTML 属性。

为了使标头有效,需要满足以下条件:
  • Onion-Location 值必须是具有 http: 或 https: 协议和 .onion 主机名的有效 URL。
  • 定义 Onion-Location 标头的网页必须通过 HTTPS 提供服务。
  • 定义 Onion-Location 标头的网页不得是洋葱站点。

在此页面上,管理 Web 服务器的命令基于类 Debian 操作系统,可能与其他系统不同。检查您的网络服务器和操作系统文档。

Apache

要在 Apache 2.2 或更高版本中配置此标头,您需要启用headers和rewrite模块并编辑网站虚拟主机文件。

步骤 1.启用标头并重写模块并重新加载 Apache2

代码:
$ sudo a2enmod headers rewrite

$ sudo systemctl reload apache2

如果您收到错误消息,则表明出现了问题,并且在弄清楚为什么不起作用之前您无法继续。

步骤 2.将 Onion-Location 标头添加到虚拟主机配置文件中

Header set Onion-Location "http://your-onion-address.onion%{REQUEST_URI}s"
其中your-onion-address.onion是您要重定向的洋葱服务地址,{REQUEST_URI}是请求的 URI 的路径组成部分,例如“/index.html”。

虚拟主机示例:

代码:
<VirtualHost *:443>
       ServerName <your-website.tld>
       DocumentRoot /path/to/htdocs

       Header set Onion-Location "http://your-onion-address.onion%{REQUEST_URI}s"

       SSLEngine on
       SSLCertificateFile "/path/to/www.example.com.cert"
       SSLCertificateKeyFile "/path/to/www.example.com.key"
     </VirtualHost>

步骤 3.重新加载 Apache

重新加载 apache2 服务,使您的配置更改生效:

代码:
$ sudo systemctl reload apache2

如果您收到错误消息,则表明出现了问题,并且在弄清楚为什么不起作用之前您无法继续。

步骤 4.测试您的洋葱位置

要测试 Onion-Location 是否正常工作,请获取网站 HTTP 标头,例如:

代码:
$ wget --server-response --spider your-website.tld

查找onion-location条目和洋葱服务地址。或者在 Tor 浏览器中打开网站,地址栏中会出现一个紫色药丸。

nginx

要配置 Onion-Location 标头,服务运营商应首先配置 Onion 服务。

步骤 1. 通过在中设置以下内容来创建洋葱服务torrc:

代码:
HiddenServiceDir /var/lib/tor/hs-my-website/
HiddenServiceVersion 3
HiddenServicePort 80 unix:/var/run/tor-hs-my-website.sock

步骤 2. 编辑网站配置文件

添加/etc/nginx/conf.d/<your-website>.confOnion-Location 标头和洋葱服务地址。例如:

代码:
add_header Onion-Location http://<your-onion-address>.onion$request_uri;

带有 Onion-Location 的配置文件应如下所示:

代码:
server {
    listen 80;
    listen [::]:80;

    server_name <your-website.tld>;

    location / {
       return 301 https://$host$request_uri;
    }

}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name <your-website.tld>;

    # managed by Certbot - https://certbot.eff.org/
    ssl_certificate /etc/letsencrypt/live/<hostname>/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/<hostname>/privkey.pem;

    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header Onion-Location http://<your-onion-address>.onion$request_uri;

    # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    access_log /var/log/nginx/<hostname>-access.log;

    index index.html;
    root /path/to/htdocs;

    location / {
            try_files $uri $uri/ =404;
    }
}

server {
        listen unix:/var/run/tor-hs-my-website.sock;

        server_name <your-onion-address>.onion;

        access_log /var/log/nginx/hs-my-website.log;

        index index.html;
        root /path/to/htdocs;
}

步骤 3. 测试网站配置

代码:
$ sudo nginx -t

Web 服务器应确认新语法正在运行:

代码:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

步骤 4. 重启nginx

代码:
$ sudo nginx -s reload

如果您收到错误消息,则表明出现了问题,并且在弄清楚为什么不起作用之前您无法继续。

步骤 5:测试您的洋葱位置

要测试 Onion-Location 是否正常工作,请获取网站 HTTP 标头,例如:

代码:
$ wget --server-response --spider your-website.tld

查找onion-location条目和洋葱服务地址。或者在 Tor 浏览器中打开网站,地址栏中会出现一个紫色药丸。

Caddy

Caddy默认情况下具有自动 HTTPS功能,因此它会配置您的 TLS 证书并为您处理 HTTP 到 HTTPS 的重定向。如果您使用的是 Caddy 2,要包含 Onion-Location 标头,请在 Caddyfile 中添加以下声明:

代码:
header Onion-Location http://<your-onion-address>.onion{path}

如果您正在运行静态站点并且环境变量中有洋葱地址$TOR_HOSTNAME,您的 Caddyfile 将如下所示:

代码:
your-website.tld

header Onion-Location http://{$TOR_HOSTNAME}{path}
root * /var/www
file_server

测试一下:

代码:
$ wget --server-response --spider your-website.tld

查找onion-location条目和洋葱服务地址。或者,在 Tor 浏览器中打开网站,地址栏中会出现一个紫色药丸。

使用 HTML<meta>属性

Onion-Location 的相同行为包括将其定义为 HTML http-equiv 属性的选项<meta>。喜欢(或需要)通过修改提供的 HTML 内容而不是添加新的 HTTP 标头来定义 Onion-Location 的网站可能会使用此功能。Onion-Location 标头相当于<meta http-equiv="onion-location" content="http://<your-onion-service-address>.onion" />添加到网页的 HTML head 元素中。替换<your-onion-service-address.onion>为您要重定向的洋葱服务。

局限性

HTML 无法读取请求的 URL 并将其动态插入到 http-equiv<meta>标记中。因此,访问者始终会被重定向到元标记内容部分中指定的 .onion URL,无论他们位于哪个子页面。

因此,如果可能的话,我们建议使用上述方法之一。