樹莓派4b部署LNMP+Tor,搭建在Dark web上的網站
- 開始前的準備
- 系統
- 下載Raspberry Pi OS
- 燒錄進TF卡
- SSH
- 打開樹莓派SSH功能
- 用Putty連接樹莓派
- 修改SSH密碼并啟用root SSH登錄
- 部署LNMP
- 安裝Nginx和PHP7
- 安裝軟體包
- 讓 Nginx 能處理 PHP
- 安裝配置MySQL
- 安裝軟體包
- 更改Mysql密碼
- 安裝并部署Tor服務
- 配置Hidden Service獲取Onion域名
- 修改權限
- 訪問網站
- 完成
- 參考資料
開始前的準備
你需要有:
- 一臺電腦
- 樹莓派4b及其必要的配件
- Putty
- Winscp
- 公網IP
要保證能科學上網
系統
下載Raspberry Pi OS
前往樹莓派官網下載Raspberry Pi OS
我這里選擇的是Raspberry Pi OS Lite,如果是其余兩個也不影響
燒錄進TF卡
前往Balena.io下載Etcher工具
安裝

燒錄系統(記得以管理員身份運行)
靜靜等待燒錄完成
SSH
打開樹莓派SSH功能
在剛剛燒錄系統的TF卡(boot盤)中新建一個沒有后綴的SSH檔案

用Putty連接樹莓派
打開Putty,連接樹莓派
使用默認賬號密碼登錄
賬號 pi
密碼 raspberry


修改SSH密碼并啟用root SSH登錄
修改pi密碼
sudo passwd pi

同理,修改root密碼,啟用root并開啟ssh登錄
sudo passwd root
sudo passwd --unlock root
sudo sed -i "s/^#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
sudo systemctl restart ssh
sudo cp ~/.bashrc /root/.bashrc

部署LNMP
安裝Nginx和PHP7
安裝軟體包
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx php7.3-fpm php7.3-cli php7.3-curl php7.3-gd php7.3-cgi
sudo service nginx start
sudo service php7.3-fpm restart
安裝成功可在http://樹莓派IP/訪問到Nginx的默認頁

Nginx的根目錄在 /var/www/html
讓 Nginx 能處理 PHP
sudo nano /etc/nginx/sites-available/default
將以下內容
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

替換為
location / {
index index.html index.htm index.php default.html default.htm default.php;
}
location ~\.php$ {
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

保存
Ctrl + O
Enter
退出
Ctrl + X
重啟Nginx
sudo service nginx restart
安裝配置MySQL
安裝軟體包
sudo apt-get install mariadb-server-10.0
更改Mysql密碼
mysql

use mysql;
update user set plugin='mysql_native_password' where user='root';
UPDATE user SET password=PASSWORD('你想要設定的密碼') WHERE user='root';
flush privileges;
exit;

重啟Mysql服務
service mysql restart
安裝并部署Tor服務
安裝Tor
sudo apt-get install tor
Tor的根目錄在 /etc/tor
配置Hidden Service獲取Onion域名
編輯 /etc/tor/torrc
sudo nano /etc/tor/torrc
找到以下內容,去掉前面的#號
############### This section is just for location-hidden services ###
## Once you have configured a hidden service, you can look at the
## contents of the file ".../hidden_service/hostname" for the address
## to tell people.
##
## HiddenServicePort x y:z says to redirect requests on port x to the
## address y:z.
HiddenServiceDir /var/lib/tor/hidden_service/ //hidden service的目錄
HiddenServicePort 80 127.0.0.1:80 //HTTP服務器IP,埠
#HiddenServiceDir /var/lib/tor/other_hidden_service/
#HiddenServicePort 80 127.0.0.1:80
#HiddenServicePort 22 127.0.0.1:22

保存
Ctrl + O
Enter
退出
Ctrl + X
重啟Tor服務
killall tor
sudo -u debian-tor tor
等待啟動,第一次啟動時間較長,要保證網路暢通

顯示以下內容即可
[notice] Bootstrapped 100%: Done

獲取Onion域名
默認在 /var/lib/tor/hidden_service/hostname
cd /var/lib/tor/hidden_service/
cat hostname

修改權限
修改 /var/www 檔案夾的權限
sudo chown -R debian-tor:www-data /var/www

再次重啟Tor服務
killall tor
sudo -u debian-tor tor
訪問網站
下載安裝Tor瀏覽器,就不多說
連接上Tor服務,訪問獲取的Onion域名

完成
參考資料
SSH——https://www.jianshu.com/p/654ee08d2b3a
LNMP——https://shumeipai.nxez.com/2020/03/21/install-pi-dashboard-with-nginx-php73-on-pi.html
Tor
——https://blog.csdn.net/kEnnponN/article/details/82662445
——https://blog.csdn.net/weixin_30721899/article/details/98115671?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
——https://tor.stackexchange.com/questions/14863/var-lib-tor-is-not-owned-by-this-user-root-0-but-by-debian-tor-110
——https://askubuntu.com/questions/833021/could-not-bind-to-127-0-0-19050-address-already-in-use-is-tor-already-running
權限修改——https://zhidao.baidu.com/question/94171636.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/289543.html
標籤:其他
下一篇:微服務原理學習小結(一)
