安装Nginx
下载nginx安装包
pi@raspberrypi:~ $ cd Downloads/
pi@raspberrypi:~/Downloads $ wget https://pan.shuaiguoer.com/Linux/packge/nginx-1.18.0.tar.gz
解包
pi@raspberrypi:~/Downloads $ tar -zxvf nginx-1.18.0.tar.gz
安装依赖
pi@raspberrypi:~/Downloads/nginx-1.18.0 $ sudo apt-get install build-essential zlib1g zlib1g-dev libpcre3 libpcre3-dev openssl libssl-dev -y
编译安装nginx
pi@raspberrypi:~/Downloads $ cd nginx-1.18.0/
pi@raspberrypi:~/Downloads/nginx-1.18.0 $ sudo ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module && sudo make && sudo make install
路径优化
pi@raspberrypi:~/Downloads/nginx-1.18.0 $ sudo ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
启动nginx
pi@raspberrypi:~/Downloads/nginx-1.18.0 $ sudo nginx
访问页面
安装 mariadb
pi@raspberrypi:~ $ sudo apt-get install mariadb-server -y
设置mariadb密码
pi@raspberrypi:~ $ sudo mysqladmin -uroot -p password
Enter password:
New password:
Confirm new password:
授权
# 登录数据库
pi@raspberrypi:~ $ mysql -uroot -p
Enter password: xxxxxx
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.3.22-MariaDB-0+deb10u1 Raspbian 10
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 授权
MariaDB [(none)]> grant all on *.* to 'root'@'192.168.1.%' identified by 'xxxxxx';
Query OK, 0 rows affected (0.001 sec)
# 刷新权限
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
创建数据库
MariaDB [(none)]> create database typecho;
Query OK, 1 row affected (0.001 sec)
# 退出
mysql> exit
mysql> Bye
安装PHP
安装PHP
pi@raspberrypi:~/Downloads/nginx-1.18.0 $ sudo apt-get install php php-fpm php-mysql -y
安装PHP扩展
pi@raspberrypi:~ $ sudo apt-get install php7.3-gd php7.3-curl php7.3-common php7.3-mbstring php7.3-mysql php7.3-xml
整合nginx与PHP
修改PHP配置文件
pi@raspberrypi:~ $ sudo vim /etc/php/7.3/fpm/pool.d/www.conf
user = nginx
group = nginx
listen = 127.0.0.1:9000
重启PHP
pi@raspberrypi:~ $ sudo service php7.3-fpm restart
修改nginx配置文件
pi@raspberrypi:~ $ sudo vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重启nginx
# 检查nginx配置文件
pi@raspberrypi:~ $ sudo nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# 重启nginx
pi@raspberrypi:~ $ sudo nginx -s reload
测试PHP是否正常解析
pi@raspberrypi:~ $ cd /usr/local/nginx/html/
pi@raspberrypi:/usr/local/nginx/html $ vim index.php
<?php
phpinfo();
?>
访问页面
安装Typecho
下载Typecho
pi@raspberrypi:~/Downloads $ wget https://pan.shuaiguoer.com/%E9%99%84%E4%BB%B6/typecho-1.1-17.10.30-release.tar.gz
解包Typecho到nginx目录下
pi@raspberrypi:~/Downloads $ sudo tar -zxvf typecho-1.1-17.10.30-release.tar.gz -C /usr/local/nginx/html/
# 移动typecho程序到nginx主目录
pi@raspberrypi:/usr/local/nginx/html $ sudo mv build/* .
pi@raspberrypi:/usr/local/nginx/html $ sudo rm -rf build/
安装Typecho
打开浏览器访问:树莓派本机IP
点击查看您的Blog
就可以看见自己的博客了
但是查看博客的控制面板等其他页面却出现了 404
解决博客报404
pi@raspberrypi:/usr/local/nginx/html $ sudo vim /usr/local/nginx/conf/nginx.conf
# 修改nginx中PHP相关代码块
location ~ [^/]\.php(/|$) {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 检车nginx配置文件是否正确
pi@raspberrypi:~ $ sudo nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# 重启nginx
pi@raspberrypi:~ $ sudo nginx -s reload
重新进入博客控制台(已经好了)
发布一篇文章试试
给树莓派安装一个漂亮的仪表盘
pi@raspberrypi:~ $ cd /usr/local/nginx/html/
pi@raspberrypi:/usr/local/nginx/html $ sudo git clone https://github.com/spoonysonny/pi-dashboard.git
pi@raspberrypi:/usr/local/nginx/html $ sudo chown -R nginx:nginx pi-dashboard/
pi@raspberrypi:/usr/local/nginx/html $ mv pi-dashboard/ view # 改名只是方便访问
然后访问: https://pi.shuaiguoer.com/view/
就可以看到自己的仪表盘了