弔祖母 107/5/27
半載才逢外公薨
七天祖母加護中
時人不解祥和面
今日亡得駕鶴蹤
/var/log/audit/audit.log
被攔截時會看見的訊息type=AVC msg=audit(1464350432.916:8222): avc: denied { getattr } for pid=17526 comm="httpd" path="/var/www/app/index.html" dev="sda1" ino=42021595 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_t:s0 tclass=file
type=SYSCALL msg=audit(1464350432.916:8222): arch=c000003e syscall=4 success=no exit=-13 a0=7fde4e450d40 a1=7ffd05e79640 a2=7ffd05e79640 a3=7fde42e43792 items=0 ppid=17524 pid=17526 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
設定存取權chcon --user system_u --type httpd_sys_content_t -Rv /your/html/path
查詢目錄的存取權ls -laZ /var/www/
正常的情形drwxr-xr-x. server server system_u:object_r:httpd_sys_content_t:s0 .
drwxr-xr-x. root root system_u:object_r:var_t:s0 ..
drwxr-xr-x. server server system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin
drwxr-xr-x. server server system_u:object_r:httpd_sys_content_t:s0 html
drwxrwxr-x. server server unconfined_u:object_r:var_t:s0 app
# Allow write only to specific dirs
chcon -t httpd_sys_rw_content_t -R your/html/path
httpd_unified 沒開的話似乎會分的更細,才會需要上面對寫入的處理,設定起來更麻煩,開起來以後只要通通給 httpd_sys_content_t ,網頁伺服器就可以完全存取了
否則你還會需要設定 httpd_sys_script_exec_t... 等權限種類,一種用途就多一個設定
113/1/25 追記 php 使用 curl 外聯被檔
最近把一個站移植到別地方想做測試站,結果所有 curl 要求都拿到空白,http code 拿到 0 ;有些是 curl 有當作 error , curl_errno($ch) 拿到 7 但是 curl_error($ch) 卻完全空白。
但這時候用指令直接執行 curl 卻又能正常取得內容。
結果找到最後也是 selinux 的問題,因為他有個設定值能阻擋網頁伺服器對外連線:
httpd_can_network_connect
查詢設定值:
# getsebool httpd_can_network_connect
若顯示 off 就表示被設成阻擋。
改成開啟,允許對外連線:
# setsebool -P httpd_can_network_connect on
打開後終於可以收到東西了。
參考:
https://stackoverflow.com/questions/50807700/apache-cannot-make-outgoing-http-requests-using-curl