2025年5月1日 星期四

自架node.js伺服器

#到自己的遊戲資料夾,安裝依存
npm init -y
npm install express socket.io 

#安裝必要元件
npm install mysql2



讓 Apache 反向代理 WebSocket 或遊戲伺服器請求

ee /usr/local/etc/apache24/httpd.conf

加入

    # --- 開始新增反向代理設定 ---

    # Proxy for HTTP requests to game server
    ProxyPass "/game/" "http://localhost:3000/"
    ProxyPassReverse "/game/" "http://localhost:3000/"

    # Proxy for WebSocket connections (Socket.IO)
    ProxyPass "/socket.io/" "http://localhost:3000/socket.io/"
    ProxyPassReverse "/socket.io/" "http://localhost:3000/socket.io/"

並將以下三列取消註解

LoadModule proxy_module libexec/apache24/mod_proxy.so
LoadModule proxy_http_module libexec/apache24/mod_proxy_http.so
LoadModule proxy_wstunnel_module libexec/apache24/mod_proxy_wstunnel.so

重新啟動

service apache24 restart

可以達成目標

只有使用者瀏覽 http://yourdomain.com/game/ 時,請求才會被轉發到你的遊戲伺服器(例如 Node.js)。

其他請求(例如首頁 http://yourdomain.com/ 或 /about.html)仍由 Apache 原本處理的靜態網頁提供。



2025年4月25日 星期五

FreeBSD 14.1架站 - 設定安全性憑證 SSL紀錄

預計使用 Let's Encrypt 免費憑證

1.先搜尋可安裝的軟體

# pkg search certbot

py311-certbot-3.1.0,1          Let's Encrypt client
py311-certbot-apache-3.1.0     Apache plugin for Certbot
py311-certbot-dns-cloudflare-3.1.0 Cloudflare DNS plugin for Certbot
py311-certbot-dns-cpanel-0.4.0_1 CPanel DNS Authenticator plugin for Certbot
py311-certbot-dns-digitalocean-3.1.0 DigitalOcean DNS Authenticator plugin for Certbot
py311-certbot-dns-dnsimple-3.1.0 DNSimple DNS Authenticator plugin for Certbot
py311-certbot-dns-dnsmadeeasy-3.1.0 DNS Made Easy DNS Authenticator plugin for Certbot
py311-certbot-dns-gandi-1.5.0_1 Gandi LiveDNS plugin for Certbot
py311-certbot-dns-gehirn-3.1.0 Gehirn Infrastructure Service DNS Authenticator plugin for Certbot
py311-certbot-dns-google-3.1.0 Google Cloud DNS Authenticator plugin for Certbot
py311-certbot-dns-linode-3.1.0 Linode DNS Authenticator plugin for Certbot
py311-certbot-dns-luadns-3.1.0 LuaDNS Authenticator plugin for Certbot
py311-certbot-dns-nsone-3.1.0  NS1 DNS Authenticator plugin for Certbot
py311-certbot-dns-ovh-3.1.0    OVH DNS Authenticator plugin for Certbot
py311-certbot-dns-powerdns-0.2.1_2 PowerDNS DNS Authenticator plugin for Certbot
py311-certbot-dns-rfc2136-3.1.0 RFC 2136 DNS Authenticator plugin for Certbot
py311-certbot-dns-route53-3.1.0 Route53 DNS Authenticator plugin for Certbot
py311-certbot-dns-sakuracloud-3.1.0 Sakura Cloud DNS Authenticator plugin for Certbot
py311-certbot-dns-standalone-1.1_1 Standalone DNS Authenticator plugin for Certbot
py311-certbot-nginx-3.1.0      NGINX plugin for Certbot

2.安裝必要軟體
pkg install py311-certbot py311-certbot-apache

3.搜尋虛擬主機設定
# grep -r "VirtualHost \*:80" /usr/local/etc/apache24/

/usr/local/etc/apache24/extra/httpd-vhosts.conf.sample:<VirtualHost *:80>
/usr/local/etc/apache24/extra/httpd-vhosts.conf.sample:<VirtualHost *:80>
/usr/local/etc/apache24/extra/httpd-vhosts.conf:<VirtualHost *:80>
/usr/local/etc/apache24/extra/httpd-vhosts.conf:<VirtualHost *:80>

4. 修改虛擬主機設定
# ee /usr/local/etc/apache24/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/www/web/"
    ServerName gen-slps.slps.tn.edu.tw
    ServerAlias gen-slps.slps.tn.edu.tw
    ErrorLog "/usr/local/www/apache24/logs/dummy-host.example.com-error_log"
    CustomLog "/usr/local/www/apache24/logs/dummy-host.example.com-access_log" common
</VirtualHost>

5. 修改 httpd.conf
# ee /usr/local/etc/apache24/httpd.conf
1. Include /usr/local/etc/apache24/extra/httpd-vhosts.conf
2. #LoadModule rewrite_module libexec/apache24/mod_rewrite.so
3. #LoadModule ssl_module libexec/apache24/mod_ssl.so

6. 安裝並設定憑證,安裝完重開 apache
certbot --apache -d gen-slps.slps.tn.edu.tw
service apache24 restart

7. 增加虛擬主機設定,強制輸入ip的使用者進入網域
<VirtualHost *:80>
    ServerName 163.26.79.1
    Redirect permanent / https://gen-slps.slps.tn.edu.tw/
</VirtualHost>

2025年2月7日 星期五

VScode安裝及中文化

1. 安裝VSCodeSetup-x64-1.52.1.exe

2. 安裝ndp48-x86-x64-allos-enu.exe

3. 畫面的左方功能列表中,可以找到 Extensions,點選後輸入 “Chinese” 即可搜尋到中文的相關語系,選擇中文(繁體)後頁面的右方即會出現相關介紹,此時按下 “Install” 就會安裝中文語系套件。

如果要玩Pyhton

4. 安裝最新版本 https://www.python.org/downloads/

5.

2025年1月29日 星期三

使用 Calibre 外掛將ePub 電子書簡轉繁

  1. 開啟 Calibre 軟體主視窗,點一下「偏好設定」按鈕再按「外掛」。
  2. 開啟外掛設定頁面後,按一下「取得新外掛」按鈕。
  3. 在「以名稱篩選」方框中輸入「chinese」再按鍵盤的「Enter」鍵,找到「Traditional <-> Simplified Chinese Converter」後按「安裝」。


  4. 安裝好外掛程式後,選取你要轉換的 ePub 文件再按「編輯書本」按鈕,開啟編輯書本視窗後執行「外掛」裡面的「Convert Chinese Text Simplified/Traditional」功能。





  5. 在「Chinese Conversion」視窗中,如果要將簡體中文轉換成繁體字的話,請選「Simplified to Traditional」,「Language Styles」裡面選「Taiwan」,按下「確定」按鈕後,即可開始轉換。

  6. 完成後請先檢查一下是不是都正常,沒問題的話按「儲存」按鈕即可完成。



2024年11月21日 星期四

FreeBSD 14.1架站紀錄

 使用檔案:FreeBSD-14.1-RELEASE-amd64-dvd1.iso

1.設定SSH

修改方式:

# vi /etc/ssh/sshd_config
PermitRootLogin yes
PermitEmptyPasswords no
PasswordAuthentication yes
Port 22(修改Port的Num)

開機啟動:

# vi /etc/rc.conf加入
sshd_enable="yes"

重新啟動服務:

# /etc/rc.d/sshd restart
AllowUsers UserName(允許特定IP或User)

2.putty字型大小調整

3.安裝Appache

(1) pkg info 第一次安裝pkg / 之後可看裝了那些套件
(2) pkg update 更新pkg
    [1] pkg search 
    [2] pkg install
    [3] pkg delete
    [4] pkg info -a   
(3) 安裝Appache
    [1] pkg search apache
    [2] pkg install apache24-2.4.62
    [3] ee /etc/rc.conf 寫入 apache24_enable="YES"
    [4] service apache24 restart
    [5] /usr/local/etc/apache24/httpd.conf    (編輯設定) 
    [6] Options Indexes FollowSymLinks >> Options FollowSymLinks    (取消觀看目錄)
    [7] DirectoryIndex index.html index.htm index.php    (預設首頁格式)
(4) 安裝Mysql
    [1] pkg search mysql
    [2] pkg install mysql84-server
    [3] ee /etc/rc.conf 寫入 mysql_enable="YES"
    [4] service mysql-server restart
    [5] service mysql-server status    //測試mysql有沒有啟動
    [6] mysql_secure_installation        //設定Mysql的root密碼和一些安全性設定
    [7] 登入Mysql : mysql -u root -p
    [8] 離開 mysql> \q
    [9] /usr/local/etc/my.cnf    (my.cnf位置)
    [10] find / -name mysql.sock           (搜尋)
    [11] ee /etc/passwd        (觀看目前帳號狀況)
    [12] mysql指令
            show databases;
            use mysql
            show tables;
            select host, user, plugin from mysql.user;    (查詢密碼的編碼)
            alter user 'root' identified with mysql_native_password by 'passwd';    (修改密碼編碼)
                (因為mysql84預設值會把mysql_native_password關閉,所以需要做以下修改)
                ee  /usr/local/etc/my.cnf                        編輯my.cnf
                mysql_native_password           = ON    加入這行
                bind-address                    = 0.0.0.0        把127.0.0.1改成0.0.0.0
            alter user 'root' IDENTIFIED BY 'passwd';    (修改密碼)
            update mysql.user set host = '%' where user = 'root';    (開放所有IP連線)
            如有失敗,先設定密碼安全程度
            {1} SHOW VARIABLES LIKE 'validate_password%';    (查詢密碼策略)
            {2} set global validate_password.policy=0;                    (修改策略)
            {3} set global validate_password.length=1;                    (修改長度)
            {4} flush privileges;    (刷新權限表)
            {5} 參考資料 https://www.cnblogs.com/baby123/p/12221405.html

(5) 啟用防火牆
    sysrc firewall_enable=YES
    sysrc firewall_quiet=YES
    sysrc firewall_type="workstation"
    sysrc firewall_myservices="22/tcp 443/tcp"
    sysrc firewall_logdeny=YES
    service ipfw start
    service ipfw status
    查看目前的防火牆設定的指令: ipfw list

4.安裝PHP
    [1] pkg install php84
    [2] pkg install mod_php84
    [3] pkg install php84-session-8.4.0.r1    (安裝session)
    [4] pkg install php84-mysqli-8.4.0.r1    (安裝Mysqli延伸套件)
    [5] pkg install php84-mbstring-8.4.0.r1    (mbstring套件)
    [6] php.ini    ( /usr/local/etc/php.ini )
        (1) ;extension=mysqli    (更改為啟用)
        (2) ;session.save_path = "/var/lib/php/session"
        (3) ;date.timezone = Asia/Taipei    (改為啟動並設定台北時間)
        (4) extension=pdo_mysql (啟用PDO功能)

    [8] https://files.phpmyadmin.net/snapshots/phpMyAdmin-6.0%2bsnapshot-all-languages.zip.sha256
        (下載最新版的phpmyadmin)
        To make phpMyAdmin available through your web site, I suggest        
        that you add something like the following to httpd.conf:                        
        Alias /phpmyadmin/ "/usr/local/www/phpMyAdmin/"                            
        <Directory "/usr/local/www/phpMyAdmin/">                                        
                Options None                                                                                    
                AllowOverride Limit                                                                        
                Require local                                                                                    
                Require host .example.com                                                                
        </Directory>                                                                                            
    [9] /var/lib/php/session    (session儲存的地方)    
    [10] pkg install php84-sodium-8.4.0.r1     (phpmyadmin會用到的套件)
    [11] ;extension=sodium    (啟用)

5.掛載新的磁碟機
    [1] gpart create -s GPT ada1
    [2] gpart add -t freebsd-ufs -a 1M ada1
    [3] newfs -U /dev/ada1p1
    [4] mkdir /newdisk            (可以修改成自己想要的資料夾名稱)
    [5] 將磁碟項目加入到 /etc/fstab,讓啟動時會自動掛載新的磁碟:
            /dev/ada1p1 /newdisk ufs rw 2 2
    [6] mount /newdisk            (手動掛載 )

6.啟用FTP
    [1] 使用 inetd
            編輯 /etc/inetd.conf,將 ftp 設定開頭的 # 移除
            ftp     stream  tcp     nowait  root    /usr/libexec/ftpd       ftpd -l
            ftp     stream  tcp6    nowait  root    /usr/libexec/ftpd       ftpd -l
    [2]  vi /etc/rc.conf               //修改 rc.conf 設定檔
             inetd_enable="YES"             //加入此行
    [3] /etc/rc.d/inetd start               //啟動 inetd 服務
    [4] telnet localhost 21                 //測試 ftp 服務是否啟動
            quit                                 //輸入 quit 離開
    [5] 修改 /etc/ftpchroot    
        ※加入使用者名稱,讓該使用者不能離開他的家目錄
    [6]  ln -s /www/web /home/chocho/web  (在家目錄建立連結)

7.安裝Samba
    [1] pkg install samba419
    [2] ee /etc/rc.conf
            nmbd_enable="YES"
            winbindd_enable="YES"
            samba_enable="YES"
            samba_server_enable="YES"
    [3] ee /usr/local/etc/smb4.conf    (創立設定檔,原本為空的)
    [root]
        comment = root's stuff
        path = /root
        public = no
        browseable = yes
        writable = yes
        printable = no
        create mask = 0755
    [4] smbpasswd -a root  (建立用戶)
    [5] cd /usr/local/etc
    [6] service samba_server start
    [7] service samba_server status

8.帳號設定
    [1] 帳號相關檔案: /etc/passwd    、    /etc/shadow
    [2] 群組(group)相關檔案: /etc/group

9.修改系統時間
    [1]  tzsetup /usr/share/zoneinfo/Asia/Taipei    (更改時區為台灣)
    [2]  ntpdate -u pool.ntp.org    (線上同步對時)

10.設定安全性憑證 SSL

2023年12月29日 星期五

中打大富翁對話邏輯備份

typegame_speech
> mode 0
>> after=0 對話直接結束
>> after>0 出現下一個選單 (通常最後會到一個 mode 1 的對話)

> mode 1
>> 出現問題選單 選單內容:
>> qus_sp 的 part
>> 正確回答問題 r_mission
>> 錯誤回答問題 w_mission
>>> 導引至任務資料庫 typegame_speech_misson
>>> mode 0
>>>> 傳送、製作、消耗物品等
>>> mode 1
>>>> 特殊任務