静看光阴荏苒
不管不顾不问不说也不念

使用Debian10在暗网搭建一个网站(onion域名)

前两篇文章水了一下Tor的节点搭建,这篇文章介绍一下Tor的另外一个功能:隐藏服务。

简单点说这个隐藏服务允许你自己注册一个onion域名,然后可以使用这个域名来创建自己的Tor网站。

隐藏服务仅在Tor的网络内部工作,所以具有onion域名的站点只能通过Tor网络来访问。

本文使用Debian10演示,通过下面的这些步骤你可以在暗网上搭建一个wordpress。

首先还是先安装tor,这里同时把nginx和mariadb也装上:

apt -y update
apt -y install tor nginx mariadb-server

因为要搭建wordpress,php也装一下:

apt -y install php7.3 php7.3-common php7.3-cli php7.3-cgi php7.3-fpm \
php7.3-gd php7.3-mysql php7.3-sqlite3 php7.3-pgsql php7.3-opcache \
php7.3-mbstring php7.3-curl php7.3-xml php7.3-xmlrpc php7.3-zip \
php7.3-intl php7.3-json php7.3-bz2

先初始化数据库:

mysql_secure_installation

现在登录到mysql内创建wordpress数据库:

mysql -u root -p
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress@localhost IDENTIFIED BY '设置你的数据库密码';
FLUSH PRIVILEGES;
quit

然后下载wordpress源码/解压/设置正确的权限:

cd /var/www
wget https://wordpress.org/latest.zip
unzip latest.zip
rm -rf latest.zip
chown -R www-data:www-data wordpress

由于我之前已经在这台机器上搭建了入口节点和中继节点,这里我其实可以把隐藏服务部署在这两个实例中,但是我不想让某一个实例同时具有这么多功能,这里就可以创建新实例:

tor-instance-create wordpress

编辑新实例的配置文件:

nano /etc/tor/instances/wordpress/torrc

写入如下配置:

HiddenServiceDir /var/lib/tor-instances/wordpress/hidden_service/
HiddenServicePort 80 127.0.0.1:58163

启动新的实例即可:

systemctl start tor@wordpress
systemctl enable tor@wordpress

查看你的onion域名:

cat /var/lib/tor-instances/wordpress/hidden_service/hostname

如果正常可以回显出你的域名,例如我的:

pf73h6t33mvp7lsbr2solnfquubswqu65tirjffpty5tmnj46erbo3qd.onion

现在我们需要编辑nginx的主配置文件:

nano /etc/nginx/nginx.conf

在http块内加入下面的配置:

server_names_hash_bucket_size 128;

位置如图所示:

目的是解决onion域名过长导致nginx启动报错。

接着新建一个nginx站点配置文件:

nano /etc/nginx/conf.d/wordpress.conf

写入如下配置:

server {
    listen       127.0.0.1:58163;
    server_name  pf73h6t33mvp7lsbr2solnfquubswqu65tirjffpty5tmnj46erbo3qd.onion;
    root   /var/www/wordpress;
    index  index.html index.php;
    client_max_body_size 100M;

    allow 127.0.0.1;
    deny all;
    server_tokens off;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/run/php/php7.3-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

这里解释一下这个nginx的配置:

1.listen这里监听127.0.0.1:58163是让这个站点只监听在本地,外部网络是访问不到这个站点的。同时58163端口对应之前tor配置里面的端口号。

2.allow 127.0.0.1和deny all是让这个站点只允许本地访问,其实配置了这段之后你可以把listen修改成监听到外网,外网其实也是访问不到这个站点的,会显示403。

3.server_name这个不用多说,替换成你自己的onion域就行。

4.server_tokens off是隐藏nginx的版本号,可选。

执行下面的命令测试nginx配置是否正常:

nginx -t

没问题的话重启nginx即可:

systemctl restart nginx
systemctl enable nginx

打开Tor浏览器访问你的onion域名就能浏览到网页了:

赞(8)
未经允许不得转载:荒岛 » 使用Debian10在暗网搭建一个网站(onion域名)
分享到: 更多 (0)

评论 10

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    把博客放在暗网这样真的好吗 ?:grin:

    Foliage4年前 (2020-06-06) Google Chrome 83.0.4103.97 Google Chrome 83.0.4103.97 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 当然不好,这只是拿wordpress演示而已。。

      LALA4年前 (2020-06-07) Google Chrome 80.0.3987.163 Google Chrome 80.0.3987.163 Windows 10 x64 Edition Windows 10 x64 Edition回复
  2. #2

    大佬你看,抄的真快
    https://bbs.secgeeker.net/thread-1558-1-1.html :mrgreen:

    DouZi4年前 (2020-06-07) Google Chrome 83.0.4103.96 Google Chrome 83.0.4103.96 Android 10 Android 10回复
    • 你要帮我重拳出击吗?

      LALA4年前 (2020-06-07) Google Chrome 80.0.3987.163 Google Chrome 80.0.3987.163 Windows 10 x64 Edition Windows 10 x64 Edition回复
  3. #3

    你的blog 已经和谐了,打不开

    无名4年前 (2020-06-11) Google Chrome 83.0.4103.97 Google Chrome 83.0.4103.97 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 欢迎来到地球

      LALA4年前 (2020-06-11) Google Chrome 80.0.3987.163 Google Chrome 80.0.3987.163 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 是呀,不怕和谐吗?

      pfttm4年前 (2020-06-14) Microsoft Edge 83.0.478.45 Microsoft Edge 83.0.478.45 Windows 10 x64 Edition Windows 10 x64 Edition回复
  4. #4

    一步步按教程搭建了,打不开啊

    4年前 (2020-09-26) Google Chrome 80.0.3987.132 Google Chrome 80.0.3987.132 GNU/Linux x64 GNU/Linux x64回复
  5. #5

    在吗

    14年前 (2020-10-06) Firefox 68.0 Firefox 68.0 Android 6.0 Android 6.0回复

分享创造快乐

广告合作资源投稿