如果你除了內建的openssl 又自行安裝比較新版的openssl
在安裝其他套件時出現以下警告訊息
/!\ WARNING /!\
You have security/openssl installed but do not have
DEFAULT_VERSIONS+=ssl=openssl set in your make.conf
解決方式
echo 'DEFAULT_VERSIONS+=ssl=openssl' >> /etc/make.conf
即可
如果你除了內建的openssl 又自行安裝比較新版的openssl
在安裝其他套件時出現以下警告訊息
/!\ WARNING /!\
You have security/openssl installed but do not have
DEFAULT_VERSIONS+=ssl=openssl set in your make.conf
解決方式
echo 'DEFAULT_VERSIONS+=ssl=openssl' >> /etc/make.conf
即可
[root@test] ~# echo stats | nc memcached-server 11211
STAT pid 16817
STAT uptime 181573
STAT time 1499060450
STAT version 1.4.4
STAT pointer_size 64
STAT rusage_user 186.459653
STAT rusage_system 581.109657
STAT curr_connections 12
STAT total_connections 163313
STAT connection_structures 71
STAT cmd_get 8260007
STAT cmd_set 811378
STAT cmd_flush 0
STAT get_hits 7935925
STAT get_misses 324082
STAT delete_misses 0
STAT delete_hits 1
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 7135925788
STAT bytes_written 14480451759
STAT limit_maxbytes 2147483648
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 283099957
STAT curr_items 211892
STAT total_items 811378
STAT evictions 0
END
^C
wget -R jpg,gif,css,js -r -l 2 --delete-after http://myip.pass.tw/ | & tee wget.log
-R: 排除某些檔案不抓
-r: 遞迴抓取網頁
-l: 抓到第幾層
--delete-after: 移除暫存網頁
網站擷取:使用Python
Web Scraping with Python
作者: Ryan Mitchell
譯者:Studio Tib.
出版社:歐萊禮
出版日期:2016/10/03
語言:繁體中文
安裝好nginx + php-fpm 後,ngixn error log出現以下錯誤訊息
2017/06/28 10:06:46 [error] 949#100116: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.77.252, server: ng.test.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "example.com:8080"
預設參考範例
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
修改為以下設定
location ~ \.php$ {
#root html;
root "你的網頁路徑";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重新啟動nginx 即可
MIS 一定要懂的82個伺服器建置與管理知識
作者: きはし まさひろ
譯者: 陳禹豪, 黃瑋婷
出版社:旗標
varnishadm
ban req.http.host == "example.com" && req.url ~ "\.png$"
假設我們的rsync server 有兩張網卡
一張對外、一張對內
如果rsync 的服務只需要對內,不希望外面的人來打擾
當然可以用防火牆來阻擋
但如果不方便用防火牆的話
也可以透過修改設定檔來達成
如果是獨立執行的
參考一下man 說明
address
You can override the default IP address the daemon will listen
on by specifying this value. This is ignored if the daemon is
being run by inetd, and is superseded by the --address com-
mand-line option.
可以修改 rsyncd.conf
address = 要LISTEN的IP
如果是透過xinetd 啟動的
可以修改 /etc/xinetd.d/rsync
加入 bind = 要LISTEN的IP
或是考慮其他參數
如
only_from 或是 only_from
cd /usr/posts/www/drupal8
make install
基本上只要一直下一步即可完成安裝流程
安裝完後會出現apache 及php 的建議設定
用Drupal輕鬆架出商業網站:網路商店╳報名平台╳預約系統╳拍賣平台
如果經營一個跨國網站
想要針對不同國家來的客戶,呈現出客製化的內容、語系
或是想要導到當地比較的機房
可以利用apache + mod_geoip + rewrite 來實現
安裝 GeoIP
cd /usr/ports/net/GeoIP
make install
GeoIP資料庫預設會放在 /usr/local/share/GeoIP
剛安裝完後是空的,必須執行已下指令下載資料庫
/usr/local/bin/geoipupdate.sh
也可以將這個指令放入crontable排程中,定時更新資料庫
crontab -e
0 0 1 * * /usr/local/bin/geoipupdate.sh
之後便下載以下兩個檔案
-r--r--r-- 1 root wheel 1.0M 5 3 05:30 GeoIP.dat
-r--r--r-- 1 root wheel 1.9M 5 3 05:30 GeoIPv6.dat
安裝 mod_geoip
cd /usr/ports/www/mod_geoip2
make install
編輯apache設定
vi /usr/local/etc/apache22/httpd.conf
LoadModule geoip_module libexec/apache22/mod_geoip.so
Include etc/apache22/extra/geoip.conf
vi /usr/local/etc/apache22/extra/geoip.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile //usr/local/share/GeoIP/GeoIP.dat
</IfModule>
重啟apache
apachectl restart
編輯rewrite rule ,如果是美國來的ip則轉址到美國網站
vi .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mybox.tw$ [NC]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://us.mybox.tw/$1 [L,R]
Python新手使用Django架站的16堂課:
活用Django Web Framework快速建構動態網站
作者: 何敏煌
出版社:博碩
下載原始檔案
https://www.openssl.org/source/
http://ftp.gnu.org/gnu/wget/
tar -zxpBvf openssl-1.0.2k.tar.gz
cd openssl-1.0.2k
./config
make
make test
make install
檢查openssl 版本
/usr/local/ssl/bin/openssl version
OpenSSL 1.0.2k 26 Jan 2017
tar -zxpBvf wget-1.19.1.tar.gz
cd wget-1.19.1
./configure --with-ssl=openssl --with-libssl-prefix=/usr/local/ssl
make
make install
收工
如果真的必須要把 linux 暴露在 internet 上
使用 ssh key 登入某種程度來說要比帳號密碼驗證來的安全多
我們可以藉由修改 /etc/ssh/sshd_config 關閉密碼驗證來限制只允許使用 ssh key 登入
PasswordAuthentication no
修改完後記得重新啟動 sshd
在 linux 上可以簡單用 ssh-keygen 產生 id_rsa
並且用 ssh-copy-id 把 authorized_key 送上遠端 server: ~user/.ssh/ 中
但是如果要在一台 windows client 透過 putty 的話
就要先下載 puttygen
1. 開啟 putty key generator
2. 點選上方 conversions - import key
3. 選擇 linux ssh-keygen 產生的 id_rsa
4. 如果有密碼的話,輸入密碼
5. save private key
鳥哥的Linux私房菜:伺服器架設篇(第三版)(附光碟)
curl --help
-I, --head Show document info only
# curl -I http://myip.pass.tw/
HTTP/1.1 200 OK
Date: Thu, 11 May 2017 06:52:20 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Connection: close
Content-Type: text/html; charset=UTF-8
圖解HTTP
varnish 是一個高效能的 reverse proxy server
假設我要觀察瀏覽器連到 varnish server 的 /abc/ 路徑時,會做的動作
可以下以下指令
varnishlog -c -m 'RxURL:^/abc/$'
使用apache 的proxypass 除了要
LoadModule proxy_module libexec/apache24/mod_proxy.so
也要
LoadModule proxy_http_module libexec/apache24/mod_proxy_http.so
不然會出現以下錯誤訊息
AH01144: No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
Laravel 5 for beginner 新手道場:優雅運用框架快速開發 PHP 網站
作者: 洪可郡(KeJyun)
出版社:博碩
假設我們只允許 192.168.0.1 及 10.38.2.1 這兩個ip可以瀏覽
其他回應 403
vi .htaccess
order deny,allow
allow from 192.168.0.1
allow from 10.38.2.1
deny from all
存檔,不用重新啟動apache 服務即可生效
WordPress架站的12堂課:網域申請x架設x佈景主題x廣告申請
如果沒有加任何參數的話
透過 crul 或是 php 的 file_get_contents() 抓取壓縮過的網頁
顯示出來的結果會是亂碼
解決方式
curl --compressed http://example.com/
或是 php 範例
$html = file_get_contents("compress.zlib://".$url);
Laravel 5 實務專題範例教學:透過框架寫出更好的PHP程式碼
首先確認 apache 設定檔
AllowOverride None
修改成
AllowOverride All
重啟apache serivce
情境1
網址列輸入 http://example.com/b/1234567890 且後面的參數為10個英數字
實際上是連結到 http://example.com/b.php?no=1234567890
vi .htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^b/(\w{10})$ "b.php?no=$1"
安裝
cd /usr/ports/databases/mysql57-server/
make install
初始化資料庫
以前會習慣下mysql_install_db,但是不是用mysql server 5.7
[root@example] /usr/local# mysql_install_db
2017-04-13 17:35:05 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-04-13 17:35:05 [ERROR] The data directory needs to be specified.
請改用以下指令,最後他會給你一組臨時密碼,請再自行修改密碼
[root@example] /usr/local# ./libexec/mysqld --initialize
100
100 200
100 200
2017-04-13T09:36:14.023452Z 0 [Warning] InnoDB: New log files created, LSN=45790
100
2017-04-13T09:36:14.264529Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
mysqld: Error on delete of './auto.cnf' (Errcode: 2 - No such file or directory)
2017-04-13T09:36:14.336677Z 0 [Warning] World-writable config file './auto.cnf' has been removed.
2017-04-13T09:36:14.336909Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a2ff2237-202c-11e7-8f2a-000c29f3f239.
2017-04-13T09:36:14.338930Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-04-13T09:36:15.160029Z 0 [Warning] CA certificate ca.pem is self signed.
2017-04-13T09:36:15.342263Z 1 [Note] A temporary password is generated for root@localhost: f-gsjI#kHHKd
啟動
/usr/local/etc/rc.d/mysql-server onerestart
未修改預設密碼前,如果要操作資料庫可能會出現以下訊息
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密碼
預設密碼會存在 /root/.mysql_secret
可以透過mysqladmin 或是 mysql_secure_installation 來修改密碼
如果出現以下錯誤訊息
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Your password has expired. To log in you must change it using a client that supports expired passwords.'
可以試試以下操作
root@localhost [(none)]> alter user 'root'@'localhost' identified by 'NEW_PASSWORD', 'root'@'localhost' password expire never;
設定開機後自動啟用
vi /etc/rc.conf
mysql_enable="YES"
圖解資料庫系統理論:使用MySQL實作
如果是apache 2.2 的設定檔直接移植到 apache 2.4 的環境可能會遇到以下的錯誤訊息
AH01630: client denied by server configuration:
解決方式請參考以下網址說明
https://httpd.apache.org/docs/2.4/upgrading.html
把
Order allow,deny
Allow From All
修改成
Require all granted
即可
新觀念 PHP7+MySQL+AJAX 網頁設計範例教本 第五版
php curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer