配件准备

  • 树莓派4B开发板
  • 32G内存卡
  • 一根网线

    选择固件

    这里我用的是Lean的树莓派openwrt固件。
    作者项目地址:https://github.com/coolsnowwolf/openwrt

刷入固件

打开工具win32,如下选择固件和磁盘位置,点击写入

写入成功后,将卡插入树莓派。启动树莓派。

登录后台

将树莓派的的网口用网线连接至自己的电脑,然后在浏览器内输入192.168.1.1,如果连接没问题的话会直接跳转到openwrt后台界面。
默认用户名:root
默认登录密码:password

添加接口

添加一个wan端口,协议为DHCP客户端,物理设置中勾选以太网适配器eth0

openwrt的优势

openwrt和其他固件不同在于,可以安装很多插件。如广告屏蔽、云盘下载加速等。

网络储存

当然,我们也可以在路由器上大家Nginx和PHP环境。也就是说我们可以将路由器搭建成为一个小型的服务器。

配置ssh

自己的东西,凭什么不能登录ssh。很多路由器固件是不能ssh登录的,而openwrt很简单。
配置ssh

登录ssh

搭建博客

修改nginx配置文件

user root root;
worker_processes  1;
pid        /var/run/nginx_kodexplorer.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8081;
        server_name  localhost;
        location / {
            root /mnt/www/;
            index index.html index.htm index.php;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root /mnt/www/;
try_files $uri = 404; # PHP 文件不存在返回404
            fastcgi_pass unix:/var/run/php7-fpm.sock; # 通过 Unix 套接字执行 PHP
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 修复 Nginx fastcgi 漏洞
            include /etc/nginx/fastcgi_params;
        }
    }
}

测试探针文件

安装typecho

这样,便将一个不起眼的路由器,搭建成为了服务器。

最后修改:2023 年 08 月 04 日
如果觉得我的文章对你有用,请随意赞赏