Skip to content

Zeroplex 生活隨筆

軟體開發、伺服器和生活瑣事

小 縮小字型大小。 中 重設字型大小。 大 放大字型大小。

月份: 2020 年 6 月

用 Nginx 設定擋掉特定的 user agent

Posted on 2020 年 6 月 21 日2021 年 6 月 25 日 By 日落 在〈用 Nginx 設定擋掉特定的 user agent〉中尚無留言

有些 bot 很討厭,掃描速度快,而且感覺在猜測網站內容,打出很多 HTTP 404:

$ grep bot access.log | awk '{print $NF}' |sort | uniq -c | sort -n | tail
    298 +http://napoveda.seznam.cz/en/seznambot-intro/)"
    525 +http://www.brandwatch.net)"
    599 +http://yandex.com/bots)"
   1005 bot@linguee.com)"
   1233 Safari/537.36"
   1421 +http://www.bing.com/bingbot.htm)"
   5335 +https://seostar.co/robot/)"
  48104 +http://www.semrush.com/bot.html)"
  81520 +http://www.google.com/bot.html)"
  93660 +http://ahrefs.com/robot/)"

參考了別人 $http_user_agent 的處理方法:

if ($http_user_agent ~* (AhrefsBot|SemrushBot)) {
    return 444;
}

另外要注意的是:

  • ~*:這個不分大小寫 (case insensitive)
  • ~:這個會區分大小寫

ps. 一般來說可以參考 HTTP status code 給 HTTP 403、444 等狀態碼,我是不爽所以給 HTTP 418

Tags:Nginx

MySQL 5.7 安裝以後無法用 root 登入

Posted on 2020 年 6 月 10 日2021 年 3 月 12 日 By 日落 在〈MySQL 5.7 安裝以後無法用 root 登入〉中尚無留言

以往都是在安裝的時候,直接請你先填寫 root 密碼,以便安裝完畢以後直接登入。
但 MySQL 5.7 認證方式有更改,即使是 root 也沒有給你預設密碼。

新的方法要使用 OS 的 root 來登入 MySQL:

$ sudo mysql -u root
....
....
....
mysql>

建立 super user 帳號:

create user zeroplex@localhost identified by 'secret';
flush privileges;

grant all privileges on *.* to zeroplex@localhost with grant option;
flush privileges;

到這邊告一段落,之後 zeroplex@localhost 就可以使用原有的方式登入了。

Tags:Linux, MySQL

Pytrhon 檢查語法是否正確的方式

Posted on 2020 年 6 月 2 日2021 年 3 月 12 日 By 日落 在〈Pytrhon 檢查語法是否正確的方式〉中尚無留言

如果是用 python 直接跑:

python3 views.py
Traceback (most recent call last):
  File "views.py", line 1, in <module>
    from django.shortcuts import render

python 執行了程式,發現 import 或是程式有用到外部 library 而導致噴錯。 

 如果只要檢查語法是否正確,需要靠 py_compile module:

python3 -m py_compile views.py
Tags:Python, 程式設計

其他

關於我  (About me)

  文章 RSS Feed

  留言 RSS Feed

Apache AWS Bash C/C++ Docker FreeBSD GCP Git Google Java JavaScript Laravel Linux Microsoft MSSQL MySQL Nginx PHP PHPUnit PostgreSQL Python Qt Ubuntu Unix Vim Web Windows WordPress XD 作業系統 分享 好站推薦 專題 攝影 新奇搞笑 新聞 旅遊 生活雜記 程式設計 網路架站 網頁設計 資訊學習 資訊安全 遊戲 音樂


創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權.