Software

NGINX 使用 X-Forwarded-For 做為真實 IP 的方式

因為安全上的考量本來使用了 allow 做為 IP 進入的限定,但是因為後來前面又掛了一道代理,所以取得的 IP 就變成必須取得 X-Forwarded-For 做為真實 IP ,查了一下 NGIXN 有一個模組是 real_ip_header,以下是用法 set_real_ip_from 192.0.0.0/8; real_ip_header X-Forwarded-For; real_ip_recursive on; set_real_ip_from <=== 允許上游的 server IP 簡單來說可以是上一道代理或是 CDN real_ip_header <=== 將真實 IP 轉為哪一種 real_ip_recursive <=== 啟動或關閉真實 IP 取得,預設是 off off 傳遞最後一台機器的 IP on 以 real_ip_header 設置的為主 以上的三個參數在 http, server, location 皆可使用

Continue Reading
Software

Nginx+PHP+WordPress

之前都是用 apacher 裝 WordPress 所以這次來試試看用 Nginx 裝 WordPress 安裝Nginx sudo apt-get install nginx 安裝PHP sudo apt-get install php php-fpm php-mysql 修改nginx site 設定 server { listen 80; listen [::]:80; #設定目錄位址 root /var/www/html; index index.php index.html index.htm; #設定 server 名稱 server_name XXX.XXX.XXX; client_max_body_size 100M; location / { #設定 Rewrite try_files $uri $uri/ /index.php?$args; } # PHP …

Continue Reading