在 Debian 服务器上部署 Wavelog

简单记录在 DigitalOcean 的 Debian 服务器上使用 Linux + Nginx + PHP + MariaDB 部署 Wavelog 的过程。

简单记录在 DigitalOcean 的 Debian 服务器上使用 Linux + Nginx + PHP + MariaDB 部署 Wavelog 的过程。

软件版本

nginx version: nginx/1.22.1
PHP 8.2.26 (cli) (built: Nov 25 2024 17:21:51) (NTS)
Zend Engine v4.2.26, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.26, Copyright (c), by Zend Technologies
mariadb  Ver 15.1 Distrib 10.11.6-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper
Wavelog Version: 1.9.1

创建 Droplets

首先在 DigitalOcean 网站上创建 Droplets 实例,很简单。 选择需要的数据中心、系统版本、配置即可。

我比较喜欢使用新加坡数据中心、Debian 12、6 刀配置、SSH 登录、开启性能监控、开启 IPv6。

等待几分钟即创建完成,在控制面版查看并记录机器的 IP。

开机后连接上去,更新软件、安装 git。

1
2
3
4
sudo apt update
sudo apt upgrade
sudo apt install git
git -v

开启 DigitalOcean 的性能监控与警告(improved metrics monitoring and alerting)

1
curl -sSL https://repos.insights.digitalocean.com/install.sh | sudo bash

安装 nginx

1
2
sudo apt install nginx
nginx -v

安装 nginx 后,浏览器打开 http://<IP>:80/ 或者 http://[<IPv6>]:80/ 应该可以看到默认的 nginx 网页。

安装 php-fpm

1
2
3
sudo apt-get install php-fpm
# sudo apt-get install php8.2-fpm
php -v

安装 wavelog 需要的 php 组件

https://github.com/wavelog/Wavelog/wiki/Installation#debian

1
sudo apt install php-curl php-mysql php-mbstring php-xml php-zip php-gd

配置网页服务

下载 wavelog

使用 git 下载 wavelog 到 /var/www/wavelog/

1
git clone https://github.com/wavelog/Wavelog.git /var/www/wavelog/ --depth 1

设置 wavelog 文件夹权限

1
2
3
4
5
6
7
8
directory=/var/www/wavelog

# debian
sudo chown -R www-data:www-data $directory

# change permissions of directories and files
sudo find $directory -type d -exec chmod 755 {} \;
sudo find $directory -type f -exec chmod 664 {} \;

Wavelog 官方的警告:

It is your responsibility to ensure you protect your system from intruders/attacks. These commands and permissions are just examples used to get Wavelog up and running and are not a guide on how to achieve a secure system. You should review these permissions after installation and make appropriate changes if you determine that finer-grained access control is needed.

关闭默认的 nginx 服务器配置

1
sudo rm -rf /etc/nginx/sites-enabled/default

复制一份默认的 nginx 服务器配置并启用

1
2
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wavelog
sudo ln -s /etc/nginx/sites-available/wavelog /etc/nginx/sites-enabled/wavelog

编辑 nginx 服务器配置

借助 nano,vim 等工具远程编辑 wavelog 的配置文件:/etc/nginx/sites-available/wavelog。 或者使用 WinScp,MobaXterm 等软件在本地编辑后上传。

默认的配置大概长这样
# /etc/nginx/sites-enabled/default
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/run/php/php-fpm.sock;
        # With php-cgi (or other tcp sockets):
        #fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#    listen 80;
#    listen [::]:80;
#
#    server_name example.com;
#
#    root /var/www/example.com;
#    index index.html;
#
#    location / {
#        try_files $uri $uri/ =404;
#    }
#}

主要修改以下几项:

  • listen 设置绑定的 IP 和端口:

    1
    2
    
        listen 80 default_server;
        listen [::]:80 default_server;
    
  • root 设置 wavelog 的文件目录:

    1
    2
    
    -    root /var/www/html;
    +    root /var/www/wavelog;
    
  • index 项增加 index.php

    1
    2
    
    -    index index.html index.htm;
    +    index index.php index.html index.htm;
    
  • 根据自己的需要在 server_name 中绑定域名:

    1
    2
    
    -    server_name _;
    +    server_name log.example.com;
    
  • 启用 PHP FastCGI:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    
        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
    
            # With php-fpm (or other unix sockets):
    -       # fastcgi_pass unix:/run/php/php-fpm.sock;
    +       fastcgi_pass unix:/run/php/php-fpm.sock;
    
            # With php-cgi (or other tcp sockets):
            # fastcgi_pass 127.0.0.1:9000;
        }
    

编辑完成后,可以使用 sudo nginx -t 检查配置是否出错,根据提示进行相应修改即可。随后使用 sudo nginx -s reload 重载 nginx 或者用 sudo systemctl restart nginx 重启 nginx,此时访问 IP 或者域名应该可以看到 Wavelog 的安装界面,表明 Nginx 和 PHP 的配置基本正常。

添加官方推荐的 nginx 配置

https://github.com/wavelog/wavelog/wiki/Webserver-Configurations#nginx

参照 Wavelog 官方 wiki 给出的 nginx 配置,添加到自己的配置中。不要忘记检查和重载。

一个完整的配置的例子
# /etc/nginx/sites-enabled/wavelog

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/wavelog;

    index index.php index.html index.htm;

    server_name wavelog.example.com;
    server_tokens off;

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

    location = /favicon.ico {
        log_not_found off;
    }

    location = /robots.txt {
        log_not_found off;
    }

    location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
        expires 7d;
    }

    location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
        add_header Access-Control-Allow-Origin "*";
        expires    7d;
    }

    ## gzip (optional)
    # gzip            on;
    # gzip_vary       on;
    # gzip_proxied    any;
    # gzip_comp_level 6;
    # gzip_types      text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;

    location ~ \.php(/|$) {
        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/run/php/php-fpm.sock;
        include                       fastcgi_params;

        # fastcgi settings
        fastcgi_buffers               8 16k;
        fastcgi_buffer_size           32k;

        # fastcgi params
        fastcgi_split_path_info       ^(.+\.php)(/.*)$;
        fastcgi_param DOCUMENT_ROOT   $realpath_root;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
    }

    location ~ /\.ht {
        deny all;
    }
}

安装数据库

安装 MariaDB

1
2
sudo apt install mariadb-server
mariadb -V

启用 MariaDB 安全设置

使用 mysql_secure_installation 工具关闭一些默认设置,提高安全性。根据提示操作即可。

1
sudo mysql_secure_installation

创建数据库

  • 进入 MariaDB 命令行界面。

    1
    
    sudo mariadb -u root -p
    
  • 创建一个名为 wavelog_db 的数据库

    1
    
    CREATE DATABASE wavelog_db;
    
  • 创建一个用户 wavelog_username,并设置密码 wavelog_password

    1
    
    CREATE USER 'wavelog_username'@localhost IDENTIFIED BY 'wavelog_password';
    

    建议使用高强度密码,并妥善保管密码。

  • 向用户 wavelog_username 授予 wavelog_db 数据库的全部权限。

    1
    
    GRANT ALL PRIVILEGES ON wavelog_db.* TO 'wavelog_username'@'localhost';
    
  • 退出 MariaDB 命令行界面。

    1
    
    QUIT
    

安装 Wavelog

浏览打开你绑定 IP 或者域名,根据网页提示对 wavelog 进行初始化。

可以看到 Pre Checks 提示部分 PHP 设置不满足要求。

修改 php-fpm 设置

打开 /etc/php/8.2/fpm/php.ini,使用搜索功能搜索相应的设置项,修改其值使其符合要求:

并重启 php-fpm :

1
sudo systemctl restart php8.2-fpm

再次打开 Wavelog install 继续进行安装。

设定 Wavelog 使用的数据库和用户

将前面创建的数据库和用户填入 Wavelog 的数据库设置中。

完成安装

随后根据提示,填入用户信息,即可完成安装。

额外的设置

设置 Wavelog 自动任务的 cron

https://github.com/wavelog/wavelog/wiki/Recommended-Cron-Jobs-and-Cronmanager

打开 crontab -e, 将

# Wavelog Master Cron
* * * * * curl --silent https://<URL-To-Wavelog>/index.php/cron/run &>/dev/null

打开 Wavelog 的 Cron Manager(https://<URL-To-Wavelog>/cron),显示 OK 即可。并在页面中启用自己需要的定时任务。

手动下载数据

新安装的 Wavelog 可能没有包含一些附加数据,例如 DXCC 地区数据、LoTW 用户数据、POTA 数据等等,可以在 Debug Information 页面(https://<URL-To-Wavelog>/debug)手动更新。如果开启了自动任务,也可以等待自动更新。

URL 美化

默认的 URL 中间会带着 /index.php/ , 参照 wiki ,在 application/config/config.php$config['index_page'] 设置为 '' 空即可删除。

修改 encryption_key

根据 https://github.com/wavelog/wavelog/wiki/Wavelog.php-Configuration-File#configuration-items , 建议修改 $config['encryption_key'] 为更复杂的字符串 。

建议

安全强化

一般情况下,安装完成后,网页服务器会暴露在公网中,服务器的所有者应当采取各种措施增强服务器的安全性,以免发生服务器被攻破、数据丢失、隐私泄露等问题。

通常来说,Wavelog 一般个人使用,没有必要将其暴露在公网当中。我个人偏向于使用 Cloudflare Tunnel 这类穿透工具进行反向代理、或者使用 Zerotier 这类组网工具进行组网以避免将服务器暴露在公网中,减少服务器被攻击的可能。

如果确需公开你的 Wavelog,你应当具备一定的服务器安全知识和技能,例如使用防火墙、配置 https、禁止通过 IP 访问、性能优化、备份数据等等。

相关命令

相关命令

查看 nginx 状态

1
sudo systemctl status nginx

查看 php-fpm 状态

1
sudo systemctl status php8.2-fpm

检查 nginx 配置

1
sudo nginx -t

重新加载 nginx

1
sudo nginx -s reload

重启 nginx

1
sudo systemctl restart nginx

重启 php-fpm

1
sudo systemctl restart php8.2-fpm
Built with Hugo
Theme Stack designed by Jimmy