็†ฑ้–€ๅˆ†้กž
 ่ผ‰ๅ…ฅไธญ…
็›ฎ้Œ„

๐Ÿง Linux Proxy Server ๆต้‡่จ˜้Œ„่ˆ‡ GoAccess ่ฆ–่ฆบๅŒ–ๅˆ†ๆž

    ๐Ÿง Linux Proxy Server ๆต้‡่จ˜้Œ„่ˆ‡ GoAccess ่ฆ–่ฆบๅŒ–ๅˆ†ๆž

    ๆœฌ็ฏ‡ๆ•™ไฝ ๆŠŠ Squid Proxy ็š„ๆต้‡็ด€้Œ„(access log)่ฝ‰ๆˆไบ’ๅ‹•ๅผๅœ–่กจๅ ฑ่กจ,ๅฟซ้€Ÿ็œ‹ๅ‡บ ๅ“ชๅฐ็”จๆˆถ็ซฏๆต้‡ๆœ€ๅคง、็†ฑ้–€็ถฒ็ซ™、HTTP ็‹€ๆ…‹็ขผ、ๅฐ–ๅณฐๆ™‚ๆฎต。ๅšๆณ•ๆŽก「่ฎ“ Squid ไปฅ Combined ๆ ผๅผ่ผธๅ‡บ → ไบค็ตฆ GoAccess ่งฃๆž」็š„็ฉฉๅฎš่ทฏ็ทš;ๅŒๆ™‚ๆไพ› ๅณๆ™‚็œ‹ๆฟ(Real-Time HTML) ่ˆ‡ ๆฏๆ—ฅ้œๆ…‹ๅ ฑ่กจ ๅ…ฉ็จฎ้ƒจ็ฝฒๆ–นๅผ。

    ๐Ÿ“ฆ ไธ€、ๅ‰็ฝฎๆขไปถ

    • ๅทฒๅฏ็”จ็š„ Squid ไปฃ็†ไธปๆฉŸ(ๅปบ่ญฐๅ…ˆๅฎŒๆˆ:ๅฎ‰่ฃ、ๅŸบๆœฌ ACL、ๅ•Ÿๅ‹•ๆธฌ่ฉฆ)。
    • ็ณป็ตฑ:Ubuntu/Debian/RHEL/CentOS/Alma/Rocky ็š†ๅฏ。
    • ๆฌŠ้™:root ๆˆ– sudo。

    ๐Ÿงพ ไบŒ、่ฎ“ Squid ็”ข็”Ÿ「Combined」้ขจๆ ผๆ—ฅ่ชŒ

    GoAccess ๅฐ COMBINED(Apache/Nginx ้€š็”จ)ๆ”ฏๆดๆœ€ๅฅฝ;ๆˆ‘ๅ€‘ๆŠŠ Squid ็š„ access.log ่ผธๅ‡บๆˆๆŽฅ่ฟ‘ Combined ็š„ๆ ผๅผ,ๅพŒ็บŒ่งฃๆžๆœ€็œๅŠ›。

    ็ทจ่ผฏ /etc/squid/squid.conf(ๆˆ–ๅฐๆ‡‰่ทฏๅพ‘)
    # 1) ๅฎš็พฉไธ€ๅ€‹ๆŽฅ่ฟ‘ Apache Combined ็š„ logformat
    #   %>a = client IP, %ui/%un = ident/user, %tl = local time,
    #   "%rm %ru HTTP/%rv" = method + URL + HTTP ็‰ˆๆœฌ
    #   %>Hs = ๆœ€็ต‚็‹€ๆ…‹็ขผ, %<st = ๅ‚ณ้€ๅคงๅฐ, Referer/User-Agent ๅ–่‡ช request header
    logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}>h"
    
    # 2) ไปฅ combined ๆ ผๅผ่ผธๅ‡บๅˆฐๆ–ฐๆช”(้ฟๅ…ๅ‹•ๅˆฐๆ—ขๆœ‰ access.log)
    access_log /var/log/squid/access_combined.log combined
    
    # (ๅฏ็•™ๅญ˜ๅŽŸ็”Ÿๆ ผๅผไฝœๅ‚™ๆด)
    # access_log /var/log/squid/access.log squid
    

    ้‡ๆ–ฐ่ผ‰ๅ…ฅ่จญๅฎš:

    sudo squid -k reconfigure
    # ๆˆ–็ณป็ตฑๅŒ–
    sudo systemctl reload squid

    ๐Ÿ›  ไธ‰、ๅฎ‰่ฃ GoAccess

    Ubuntu / Debian
    sudo apt update
    sudo apt install -y goaccess
    RHEL / CentOS / Alma / Rocky(ๅปบ่ญฐๅ•Ÿ็”จ EPEL)
    sudo dnf install -y epel-release
    sudo dnf install -y goaccess

    ๐Ÿ” ๅ››、ๅฟซ้€Ÿ่ฉฆ่ท‘(็ต‚็ซฏ็‰ˆๅ ฑ่กจ)

    # ไปฅ COMBINED ๆ ผๅผ่งฃๆž Squid ็”ข็”Ÿ็š„ๆ–ฐๆช”
    sudo goaccess /var/log/squid/access_combined.log \
      --log-format=COMBINED \
      --date-format=%d/%b/%Y --time-format=%T

    ็•ซ้ขๅฐ‡้กฏ็คบ็ธฝ่ฆฝ、็†ฑ้–€ URL、็”จๆˆถ็ซฏ IP、ๆ™‚ๆฎตๅˆ†ไฝˆ、HTTP ็‹€ๆ…‹็ญ‰。

    ๐Ÿ“Š ไบ”、่ผธๅ‡บ HTML ๅ ฑ่กจ(้œๆ…‹ๆช”)

    # ็”ข็”Ÿไธ€ๆฌกๆ€ง HTML ๅ ฑ่กจ
    sudo mkdir -p /var/www/html/reports
    sudo goaccess /var/log/squid/access_combined.log \
      --log-format=COMBINED \
      --date-format=%d/%b/%Y --time-format=%T \
      -o /var/www/html/reports/proxy-report.html

    ็”จ็€่ฆฝๅ™จ้–‹ๅ•Ÿ http(s)://<ไฝ ็š„ไผบๆœๅ™จ>/reports/proxy-report.html ๅณๅฏๆŸฅ็œ‹。

    ๐Ÿ“ก ๅ…ญ、ๅณๆ™‚ๅ„€่กจๆฟ(Real-Time HTML)

    ้œ€่ฆ WebSocket ๆœๅ‹™ๆŒ็บŒ้คต่ณ‡ๆ–™。ไปฅไธ‹ไปฅ「ๅ‰็ซฏ Nginx / ๅพŒ็ซฏ GoAccess」็คบไพ‹:

    1) ็›ดๆŽฅๅ•Ÿๅ‹• GoAccess ๅณๆ™‚ๅพŒ็ซฏ(ๅธธ้ง)
    sudo goaccess /var/log/squid/access_combined.log \
      --log-format=COMBINED \
      --date-format=%d/%b/%Y --time-format=%T \
      --real-time-html \
      -o /var/www/html/reports/proxy-rt.html \
      --daemonize
    2) (ๅฏ้ธ)Nginx ๅๅ‘ไปฃ็† WebSocket(่‹ฅ่ตฐ 80/443 ๅฐๅค–)
    # /etc/nginx/conf.d/goaccess.conf
    server {
      listen 80;
      server_name _;
    
      location /reports/ {
        root /var/www/html;
      }
    
      # GoAccess ๅ…งๅปบ WS ้ ่จญ :7890(้œ€ไพๅฏฆ้š›้กฏ็คบ่ชฟๆ•ด)
      location /ws/ {
        proxy_pass http://127.0.0.1:7890/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
      }
    }
    sudo nginx -t && sudo systemctl reload nginx

    ⏰ ไธƒ、ๆฏๆ—ฅ่‡ชๅ‹•ๅŒฏๅ‡บ(systemd ็‰ˆ)

    ็”ขๅ‡บ ๆฏๅคฉไธ€ไปฝ้œๆ…‹ HTML,ๅˆฉๆ–ผ็•™ๅญ˜่ˆ‡ๅˆ†ไบซ。

    ๅปบ็ซ‹ service ่ˆ‡ timer
    # /etc/systemd/system/goaccess-report.service
    [Unit]
    Description=Daily GoAccess Report (Squid Combined)
    After=network-online.target
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/goaccess /var/log/squid/access_combined.log \
      --log-format=COMBINED \
      --date-format=%d/%b/%Y --time-format=%T \
      -o /var/www/html/reports/proxy-report-$(date +%%F).html
    
    # /etc/systemd/system/goaccess-report.timer
    [Unit]
    Description=Run GoAccess daily at 02:10
    
    [Timer]
    OnCalendar=*-*-* 02:10:00
    Persistent=true
    RandomizedDelaySec=90
    
    [Install]
    WantedBy=timers.target
    
    # ๅฅ—็”จ่ˆ‡ๅ•Ÿ็”จ
    sudo systemctl daemon-reload
    sudo systemctl enable --now goaccess-report.timer
    systemctl list-timers --all | grep goaccess

    ๐Ÿ—บ ๅ…ซ、(ๅฏ้ธ)ๅŠ ไธŠๅœฐ็†ไฝ็ฝฎ็ตฑ่จˆ

    ่‹ฅ็ทจ่ญฏ/ๅฅ—ไปถๆ”ฏๆด GeoIP2,ๅฏๅŠ ๅ…ฅๅŸŽๅธ‚/ๅœ‹ๅฎถ็ถญๅบฆ。

    # ไปฅ Debian/Ubuntu ็‚บไพ‹
    sudo apt install -y geoipupdate
    # ๅ–ๅพ— MaxMind ๅธณ่™Ÿ/้‡‘้‘ฐๅพŒ่จญๅฎš /etc/GeoIP.conf,ๅ†ๆ›ดๆ–ฐ่ณ‡ๆ–™ๅบซ
    sudo geoipupdate
    
    # ๆŒ‡ๅฎš่ณ‡ๆ–™ๅบซ(่ทฏๅพ‘ไพ็™ผ่กŒ็‰ˆไธๅŒ)
    sudo goaccess /var/log/squid/access_combined.log \
      --log-format=COMBINED \
      --date-format=%d/%b/%Y --time-format=%T \
      --geoip-database=/usr/share/GeoIP/GeoLite2-City.mmdb \
      -o /var/www/html/reports/proxy-report-geo.html

    ๐Ÿงน ไน、้šฑ็ง่ˆ‡ๅŽป่ญ˜ๅˆฅๅŒ–(ๅˆ†ไบซๅ‰ๅปบ่ญฐ)

    • ๅŽปๅฐพ็ขผๅŒ– IP:ๅˆ†ไบซๅ‰ไปฅๆœ€ๅพŒไธ€ๆฎต้ฎ็ฝฉ(ไพ‹:192.168.1.xxx)。
    • ๆŽ’้™คๅ…ง้ƒจ็ถฒๅ€:GoAccess ๆ”ฏๆด --ignore-panel ๆˆ–ๅ…ˆ่กŒไปฅ grep -v ้Žๆฟพ。
    • ไฟ็•™ๅŽŸๅง‹ๆช”:ๅ ฑ่กจๅฏๅ…ฌ้–‹,ๅŽŸๅง‹ๆ—ฅ่ชŒๅƒ…็•™ๅ…ง้ƒจ。
    ็ฏ„ไพ‹:้ฎ็ฝฉๆœ€ๅพŒไธ€ๆฎต IP ๅ†้คต็ตฆ GoAccess
    awk '{sub(/\.[0-9]+(\]| )/,".xxx"$1); print}' /var/log/squid/access_combined.log \
      > /var/log/squid/access_combined_masked.log
    
    goaccess /var/log/squid/access_combined_masked.log \
      --log-format=COMBINED -o /var/www/html/reports/proxy-report-masked.html

    ๐Ÿงฏ ๅ、ๅธธ่ฆ‹้Œฏ่ชคๆŽ’ๆŸฅ

    • ๆ™‚้–“/ๆ—ฅๆœŸ็„กๆณ•่งฃๆž:็ขบ่ช --date-format=%d/%b/%Y --time-format=%T ่ˆ‡ๆ—ฅ่ชŒ็š„ [10/Nov/2025:13:47:20 +0700] ้ขจๆ ผไธ€่‡ด。
    • ๅ ฑ่กจ็ฉบ็ฉบ็š„:ๆชขๆŸฅ access_combined.log ๆ˜ฏๅฆๆœ‰ๆ–ฐ่กŒๅฏซๅ…ฅ,ๆˆ–ๆ˜ฏๅฆไฝฟ็”จไบ†้Œฏ่ชค็š„ๆช”ๅ。
    • ๅณๆ™‚ๅ ฑ่กจ็„กๆ›ดๆ–ฐ:็€่ฆฝๅ™จ Console ็œ‹็œ‹ WS ๆ˜ฏๅฆ่ขซๆ“‹;ๅฟ…่ฆๆ™‚่จญๅฎšๅไปฃๆˆ–้–‹ๆ”พ 7890。
    • ๆฌŠ้™ๅ•้กŒ:่ฎ“ goaccess ่ƒฝ่ฎ€ๅ– /var/log/squid,ๆˆ–ไปฅ sudo ๅŸท่กŒ。

    ๐Ÿงญ ่กŒๅ‹•ๆธ…ๅ–ฎ

    ✅ ่ชฟๆ•ด squid.conf ่ฎ“ access_combined.log ็”Ÿๆˆ
    ✅ ๅฎ‰่ฃ GoAccess ไธฆๆธฌ่ฉฆ็ต‚็ซฏๅ ฑ่กจ
    ✅ ็”ขๅ‡บ HTML ๅ ฑ่กจ,ๆ”พๅˆฐ /var/www/html/reports/
    ✅ (ๅฏ้ธ)ๅ•Ÿ็”จ --real-time-html ๅณๆ™‚็œ‹ๆฟ
    ✅ (ๅฏ้ธ)ๅปบ็ซ‹ systemd timer ๆฏๆ—ฅ่‡ชๅ‹•ๅŒฏๅ‡บ
      

    ๐Ÿ“˜ ็ต่ชž

    ไปฅ Combined ๆ—ฅ่ชŒๆ ผๅผ + GoAccess ็š„ๆ–นๅผ,่ƒฝๅœจไธๆ›ดๅ‹•ๆœๅ‹™ๆ ธๅฟƒๆžถๆง‹ไธ‹,ๅฟซ้€Ÿๆ“ๆœ‰ๅฏ่ฆ–ๅŒ–ๆต้‡็ธฝ่ฆฝ;ๆญ้… systemd ๅฎšๆ™‚ ๆˆ– ๅณๆ™‚ๅ„€่กจๆฟ,ๆ—ฅๅธธ็ถญ้‹่ˆ‡็•ฐๅธธๆŽ’ๆŸฅๆœƒๆ›ด็›ด่ฆบ。


    ๐Ÿ’ฌ ไบ’ๅ‹•็•™่จ€ๅผ•ๅฐŽ

    ้€™็ฏ‡ๆœ‰ๅนซๅˆฐไฝ ๅ—Ž?ไฝฟ็”จ็š„ๆ˜ฏ ๅณๆ™‚็œ‹ๆฟ ้‚„ๆ˜ฏ ๆฏๆ—ฅๅ ฑ่กจ ๅ‘ข?็•™่จ€ๅˆ†ไบซไฝ ็š„้ƒจ็ฝฒๆ–นๅผ่ˆ‡้‡ๅˆฐ็š„ๅ‘,ๆˆ‘ๆœƒๆŠŠๅธธ่ฆ‹ๅ•้กŒๆ•ด็†ๅˆฐๆ–‡ๆœซ FAQ!

    ๐Ÿ”— ๅปถไผธ้–ฑ่ฎ€

    — WWFandy・ไธป้กŒ็ญ†่จ˜

    ๐Ÿ”— ๅˆ†ไบซ้€™็ฏ‡ LINE Facebook X

    ๆฒ’ๆœ‰็•™่จ€:

    ๅผต่ฒผ็•™่จ€

    ๅญ—็ดš