<Directory /data/wwwroot/www.123.com> SetEnvIfNoCase Referer "http://www.123.com" local_ref SetEnvIfNoCase Referer "http://123.com" local_ref SetEnvIfNoCase Referer "^$" local_ref <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)"> Order Allow,Deny Allow from env=local_ref </filesmatch> </Directory>
防盜鏈,就是不讓別人盜用你網站上的資源,這個資源,一般指的是圖片、視頻、歌曲、文檔等。php
你經過A網站的一個頁面http://a.com/a.html 裏面的連接去訪問B網站的一個頁面http://b.com/b.html ,那麼這個B網站頁面的referer就是http://a.com/a.html。 也就是說,一個referer其實就是一個網址。html
[root@xuexi-001 ~]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf //添加如下內容 <Directory /data/wwwroot/111.com> SetEnvIfNoCase Referer "http://111.com" local_ref SetEnvIfNoCase Referer "http://111.com" local_ref # SetEnvIfNoCase Referer "^$" local_ref <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png)"> Order Allow,Deny Allow from env=local_ref </filesmatch> </Directory>
解釋說明:python
首先定義容許訪問連接的referer,其中^$爲空referer,當直接在瀏覽器裏輸入圖片地址去訪問它時,它的referer就爲空。而後又使用filesmatch來定義須要保護的文件類型,訪問txt、doc、mp三、zip、rar、jpg、gif、png格式的文件,當訪問這樣的類型文件時就會被限制。linux
[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful httpd not running, trying to start
瀏覽器訪問:http://111.com/baidu.png程序員
在其它網站上連接這個網址,仍是打不開。 shell
而後在虛擬主機配置文件裏把第三方站點加入到白名單apache
<Directory /data/wwwroot/111.com> SetEnvIfNoCase Referer "http://111.com" local_ref SetEnvIfNoCase Referer "http://ask.apelearn.com" local_ref # SetEnvIfNoCase Referer "^$" local_ref <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png)"> Order Allow,Deny Allow from env=local_ref </filesmatch> </Directory>
若是想要直接能夠在網站上訪問須要配置以下:api
<Directory /data/wwwroot/111.com> SetEnvIfNoCase Referer "http://111.com" local_ref SetEnvIfNoCase Referer "http://ask.apelearn.com" local_ref SetEnvIfNoCase Referer "https://user.qzone.qq.com/328713187/infocenter" local_ref SetEnvIfNoCase Referer "^$" local_ref // 將此行的#去掉 <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png)"> Order Allow,Deny Allow from env=local_ref </filesmatch> </Directory>
[root@xuexi-001 111.com]# curl -x192.168.5.130:80 http://111.com/baidu.jpg -I HTTP/1.1 200 OK Date: Sat, 30 Jun 2018 14:27:16 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Last-Modified: Thu, 28 Jun 2018 16:33:20 GMT ETag: "30ed-56fb64a095b87" Accept-Ranges: bytes Content-Length: 12525 Content-Type: image/jpeg
[root@xuexi-001 111.com]# curl -e "http://www.qq.com/123.txt" -x192.168.5.130:80 111.com/baidu.jpg -I HTTP/1.1 403 Forbidden Date: Sat, 30 Jun 2018 14:35:11 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Content-Type: text/html; charset=iso-8859-1 [root@xuexi-001 111.com]# curl -e "http://111.com/123.txt" -x192.168.5.130:80 111.com/baidu.jpg -I HTTP/1.1 200 OK Date: Sat, 30 Jun 2018 14:35:34 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Last-Modified: Thu, 28 Jun 2018 16:33:20 GMT ETag: "30ed-56fb64a095b87" Accept-Ranges: bytes Content-Length: 12525 Content-Type: image/jpeg
說明 : 自定義referer 格式 :http://瀏覽器
對於一些比較重要的網站內容,除了可使用用戶認證限制訪問以外,還能夠經過其餘一些方法作到限制,好比能夠限制IP,也能夠限制user_agent,限制IP指的是限制訪問網站的來源IP,而限制user_agent,一般用來限制惡意或者不正常的請求。安全
[root@xuexi-001 111.com]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf <Directory /data/wwwroot/111.com/admin/> Order deny,allow Deny from all Allow from 127.0.0.1 </Directory>
解釋說明:
使用<Directory>來指定要限制訪問的目錄,order定義控制順序,哪一個在前面就先匹配哪一個規則,在本例中deny在前面,因此要先匹配Deny from all,這樣全部的來源IP都會被限制,而後匹配Allow from 127.0.0.1,這樣又容許了127.0.0.1這個IP。最終的效果是,只容許來源IP爲127.0.0.1的訪問。
[root@xuexi-001 111.com]# mkdir admin [root@xuexi-001 111.com]# cd admin/ [root@xuexi-001 admin]# touch index.php [root@xuexi-001 admin]# ls index.php [root@xuexi-001 admin]# echo "12121" > index.php [root@xuexi-001 admin]# cat index.php 12121 [root@xuexi-001 admin]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 admin]# /usr/local/apache2/bin/apachectl graceful [root@xuexi-001 admin]# curl -x 127.0.0.1:80 111.com/admin/index.php -I HTTP/1.1 200 OK Date: Sat, 30 Jun 2018 14:55:59 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 X-Powered-By: PHP/5.6.36 Content-Type: text/html; charset=UTF-8 [root@xuexi-001 admin]# curl -x 127.0.0.1:80 111.com/admin/index.php 12121
使用其餘IP 訪問 則被限制
[root@xuexi-001 admin]# curl -x 192.168.5.130:80 111.com/admin/index.php -I HTTP/1.1 403 Forbidden Date: Sat, 30 Jun 2018 14:58:08 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Content-Type: text/html; charset=iso-8859-1
查看訪問日誌
[root@xuexi-001 admin]# curl -x 127.0.0.1:80 111.com/admin/index.php -I HTTP/1.1 200 OK Date: Sat, 30 Jun 2018 15:04:17 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 X-Powered-By: PHP/5.6.36 Content-Type: text/html; charset=UTF-8 [root@xuexi-001 admin]# curl -x 127.0.0.1:80 111.com/admin/index.php 12121 [root@xuexi-001 admin]# curl -x 192.168.5.130:80 111.com/admin/index.php <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /admin/index.php on this server.<br /> </p> </body></html> [root@xuexi-001 admin]# curl -x 192.168.5.130:80 111.com/admin/index.php -I HTTP/1.1 403 Forbidden Date: Sat, 30 Jun 2018 15:04:36 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Content-Type: text/html; charset=iso-8859-1 [root@xuexi-001 admin]# tail /usr/local/apache2/logs/111.com-access_20180630.log 192.168.5.1 - - [30/Jun/2018:21:46:54 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "http://111.com/baidu.jpg" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36" 127.0.0.1 - - [30/Jun/2018:23:04:17 +0800] "HEAD HTTP://111.com/admin/index.php HTTP/1.1" 200 - "-" "curl/7.29.0" 127.0.0.1 - - [30/Jun/2018:23:04:20 +0800] "GET HTTP://111.com/admin/index.php HTTP/1.1" 200 6 "-" "curl/7.29.0" 192.168.5.130 - - [30/Jun/2018:23:04:30 +0800] "GET HTTP://111.com/admin/index.php HTTP/1.1" 403 224 "-" "curl/7.29.0" 192.168.5.130 - - [30/Jun/2018:23:04:36 +0800] "HEAD HTTP://111.com/admin/index.php HTTP/1.1" 403 - "-" "curl/7.29.0"
解釋說明:
本機有兩個IP,一個是192.168.5.130,一個是127.0.0.1,經過這兩個IP均可以訪問到站點.而來源分別爲192.168.5.130和127.0.0.1,其實和本機IP是同樣的,curl測試狀態碼爲403則被限制訪問了。
針對某個文件來作限制。
配置文件內容:
<Directory /data/wwwroot/www.123.com> <FilesMatch "admin.php(.*)"> Order deny,allow Deny from all Allow from 127.0.0.1 </FilesMatch> </Directory>
[root@xuexi-001 ~]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf <Directory /data/wwwroot/111.com> <FilesMatch "admin.php(.*)"> Order deny,allow Deny from all Allow from 127.0.0.1 </FilesMatch> </Directory>
[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful
[root@xuexi-001 ~]# curl -x192.168.5.130:80 'http://111.com/admin.php?/asdqwe' -I HTTP/1.1 403 Forbidden Date: Sat, 30 Jun 2018 15:20:41 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Content-Type: text/html; charset=iso-8859-1 [root@xuexi-001 ~]# curl -x192.168.5.130:80 'http://111.com/admin/asdqwe' -I HTTP/1.1 404 Not Found Date: Sat, 30 Jun 2018 15:20:56 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Content-Type: text/html; charset=iso-8859-1
對於使用PHP語言編寫的網站,有一些目錄是有需求上傳文件的,好比服務器能夠上傳圖片,而且沒有作防盜鏈,因此就會被人家當成了一個圖片存儲服務器,而且盜用帶寬流量。若是網站代碼有漏洞,讓上傳了一個用PHP代碼寫的,因爲網站能夠執行PHP程序,最終會讓***拿到服務器權限,爲了不這種狀況發生,咱們須要把能上傳文件的目錄直接禁止解析PHP代碼(不用擔憂會影響網站訪問,若這種目錄也須要解析PHP,那說明程序員不合格)
[root@xuexi-001 ~]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf <Directory /data/wwwroot/111.com/upload> php_admin_flag engine off <FilesMatch (.*)\.php(.*)> Order allow,deny Deny from all </FilesMatch> </Directory>
[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful
測試以前 須要先將如下幾行先禁止掉
<Directory /data/wwwroot/111.com/upload> php_admin_flag engine off # <FilesMatch (.*)\.php(.*)> # Order allow,deny # Deny from all # </FilesMatch> </Directory>
[root@xuexi-001 ~]# cd /data/wwwroot/111.com/ [root@xuexi-001 111.com]# ls 123.php admin baidu.jpg index.php [root@xuexi-001 111.com]# mkdir upload [root@xuexi-001 111.com]# cp 123.php upload/ [root@xuexi-001 111.com]# ls upload/ 123.php [root@xuexi-001 111.com]# curl -x 127.0.0.1:80 'http://111.com/upload/123.php' <?php echo"123.php"; ?>
將以前禁止掉的內容取消禁止以後測試
[root@xuexi-001 111.com]# curl -x 127.0.0.1:80 'http://111.com/upload/123.php' <?php echo"123.php"; ?> [root@xuexi-001 111.com]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 111.com]# /usr/local/apache2/bin/apachectl graceful [root@xuexi-001 111.com]# curl -x 127.0.0.1:80 'http://111.com/upload/123.php' <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /upload/123.php on this server.<br /> </p> </body></html> [root@xuexi-001 111.com]# curl -x 127.0.0.1:80 'http://111.com/upload/123.php' -I HTTP/1.1 403 Forbidden Date: Sat, 30 Jun 2018 15:53:59 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Content-Type: text/html; charset=iso-8859-1
user_agent能夠理解爲瀏覽器標識,針對user_agent來限制一些訪問,好比能夠限制一些不太友好的搜索引擎「爬蟲」,你之因此能在百度搜到一些論壇,就是由於百度會派一些「蜘蛛爬蟲」過來抓取網站數據。「蜘蛛爬蟲」抓取數據相似於用戶用瀏覽器訪問網站,當「蜘蛛爬蟲」太多或者訪問太頻繁,就會浪費服務器資源。另外,也能夠限制惡意請求,這種惡意請求咱們一般稱做cc***,他的原理很簡單,就是用不少用戶的電腦同時訪問同一個站點,當訪問量或者頻率達到必定層次,會耗盡服務器資源,從而使之不能正常提供服務。這種cc其實有很明顯的規律,其中這些惡意請求的user_agent相同或者類似,那咱們就能夠經過限制user_agent發揮防的做用。
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR] RewriteCond %{HTTP_USER_AGENT} .*baidu.com.* [NC] RewriteRule .* - [F] </IfModule>
[root@xuexi-001 111.com]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR] RewriteCond %{HTTP_USER_AGENT} .*baidu.com.* [NC] RewriteRule .* - [F] </IfModule>
[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful
[root@xuexi-001 111.com]# curl -x 127.0.0.1:80 'http://111.com/upload/123.php' -I HTTP/1.1 403 Forbidden Date: Sat, 30 Jun 2018 16:04:23 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Content-Type: text/html; charset=iso-8859-1 [root@xuexi-001 111.com]# curl -x 127.0.0.1:80 'http://111.com/123.php' -I HTTP/1.1 403 Forbidden Date: Sat, 30 Jun 2018 16:04:32 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 Content-Type: text/html; charset=iso-8859-1
[root@xuexi-001 111.com]# curl -A "xuexi xuexi" -x 127.0.0.1:80 'http://111.com/123.php' -I HTTP/1.1 200 OK Date: Sat, 30 Jun 2018 16:11:14 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 X-Powered-By: PHP/5.6.36 Content-Type: text/html; charset=UTF-8 [root@xuexi-001 111.com]# tail /usr/local/apache2/logs/111.com-access_20180701.log 127.0.0.1 - - [01/Jul/2018:00:04:23 +0800] "HEAD http://111.com/upload/123.php HTTP/1.1" 403 - "-" "curl/7.29.0" 127.0.0.1 - - [01/Jul/2018:00:04:32 +0800] "HEAD http://111.com/123.php HTTP/1.1" 403 - "-" "curl/7.29.0" 127.0.0.1 - - [01/Jul/2018:00:08:43 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "xuexi" 127.0.0.1 - - [01/Jul/2018:00:10:34 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "xuexi" 127.0.0.1 - - [01/Jul/2018:00:11:14 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "xuexi xuexi"
解釋說明:
經常使用配置選項:
使用參數 -A 指定了它的user_agent後就能夠訪問。
使用參數 -e 指定referer
使用參數 -x 相對省略本地綁定hosts
使用參數 -I 查看狀態碼
雖然PHP是以httpd一個模塊的形式存在,可是PHP自己也有本身的配置文件。
[root@xuexi-001 111.com]# ls 123.php admin baidu.jpg index.php upload [root@xuexi-001 111.com]# vi index.php //編輯index文件,輸入如下內容,保存退出。 <?php phpinfo(); ?>
瀏覽器訪問:http://111.com/index.php
複製源碼包裏開發配置文件
[root@xuexi-001 etc]# cd /usr/local/src/php-5.6.36 [root@xuexi-001 php-5.6.36]# ls acinclude.m4 main README.PARAMETER_PARSING_API aclocal.m4 makedist README.REDIST.BINS build Makefile README.RELEASE_PROCESS buildconf Makefile.frag README.SELF-CONTAINED-EXTENSIONS buildconf.bat Makefile.fragments README.STREAMS CODING_STANDARDS Makefile.gcov README.SUBMITTING_PATCH config.guess Makefile.global README.TESTING config.log Makefile.objects README.TESTING2 config.nice makerpm README.UNIX-BUILD-SYSTEM config.status meta_ccld README.WIN32-BUILD-SYSTEM config.sub missing run-tests.php configure mkinstalldirs sapi configure.in modules scripts CREDITS netware server-tests-config.php ext NEWS server-tests.php EXTENSIONS pear snapshot footer php5.spec stamp-h.in generated_lists php5.spec.in stub.c genfiles php.gif tests header php.ini-development travis include php.ini-production TSRM INSTALL README.EXT_SKEL UPGRADING install-sh README.GIT-RULES UPGRADING.INTERNALS libphp5.la README.input_filter vcsclean libs README.MAILINGLIST_RULES win32 libtool README.md Zend LICENSE README.namespaces ltmain.sh README.NEW-OUTPUT-API [root@xuexi-001 php-5.6.36]# cp php.ini-development /usr/local/php/etc/php.ini cp:是否覆蓋"/usr/local/php/etc/php.ini"? y [root@xuexi-001 php-5.6.36]# /usr/local/apache2/bin/apachectl graceful
解釋說明:
php.ini爲PHP的配置文件,能夠看出其在/usr/local/php/etc/php.ini
PHP有諸多的內置的函數,有一些函數(好比exec)會直接調取linux的系統命令,若是開放將會很是危險,所以,基於安全考慮應該把一些存在安全風險的函數禁掉。
示例以下:
[root@xuexi-001 php-5.6.36]# vi /usr/local/php/etc/php.ini //搜索disable_functions,編輯加上以下函數 eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close,phpinfo [root@xuexi-001 php-5.6.36]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 php-5.6.36]# /usr/local/apache2/bin/apachectl graceful
[root@xuexi-001 php-5.6.36]# vi /usr/local/php/etc/php.ini //找到date.timezone 定義以下: date.timezone = Asia/Shangahi(或Chongqing) [root@xuexi-001 php-5.6.36]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 php-5.6.36]# /usr/local/apache2/bin/apachectl graceful
PHP的日誌對於程序員來說很是重要,它是排查問題的重要手段。
若是加上了phpinfo函數後,瀏覽器上訪問http://111.com/index.php 就會有信息輸出,這樣也暴露的地址目錄,相對來講也不安全,咱們須要把報錯信息也隱藏掉,操做以下:
[root@xuexi-001 php-5.6.36]# vi /usr/local/php/etc/php.ini //搜索display_errors 定義以下: display_errors = Off [root@xuexi-001 php-5.6.36]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 php-5.6.36]# /usr/local/apache2/bin/apachectl graceful
使用curl 測試
[root@xuexi-001 php-5.6.36]# curl -A "a" -x127.0.0.1:80 http://111.com/index.php [root@xuexi-001 php-5.6.36]# curl -A "a" -x127.0.0.1:80 http://111.com/index.php -I HTTP/1.1 200 OK Date: Sun, 01 Jul 2018 15:40:37 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 X-Powered-By: PHP/5.6.36 Content-Type: text/html; charset=UTF-8
總結:配置了display_errors = Off後,瀏覽器訪問沒有任何輸出信息,一片空白,使用curl輸出也是同樣,這樣咱們就沒法判斷是否有問題,因此須要配置錯誤日誌。
修改配置日誌示例以下:
[root@xuexi-001 php-5.6.36]# vi /usr/local/php/etc/php.ini //搜索log_errors 改成 log_errors =On //搜索error_log 改成 /tmp/php_errors.log //搜索error_reporting 改成 error_reporting = E_ALL & ~E_NOTICE //搜索display_errors 改成 display_errors = Off [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful [root@xuexi-001 ~]# curl -A "a" -x127.0.0.1:80 http://111.com/index.php [root@xuexi-001 ~]# ls /tmp/ pear php_errors.log systemd-private-85c5235a6be24b64a7b2f04d7e89bbe1-chronyd.service-1yQ32M systemd-private-85c5235a6be24b64a7b2f04d7e89bbe1-vgauthd.service-JwsZ3V systemd-private-85c5235a6be24b64a7b2f04d7e89bbe1-vmtoolsd.service-FHWlxm [root@xuexi-001 ~]# ls -l /tmp/php_errors.log -rw-r--r-- 1 daemon daemon 135 7月 1 23:57 /tmp/php_errors.log [root@xuexi-001 ~]# ps aux |grep httpd root 1440 0.0 0.6 259952 12828 ? Ss 7月01 0:00 /usr/local/apache2/bin/httpd -k graceful daemon 3094 0.0 0.5 546780 9544 ? Sl 7月01 0:00 /usr/local/apache2/bin/httpd -k graceful daemon 3095 0.0 0.6 612316 12360 ? Sl 7月01 0:00 /usr/local/apache2/bin/httpd -k graceful daemon 3096 0.0 0.5 546780 9544 ? Sl 7月01 0:00 /usr/local/apache2/bin/httpd -k graceful root 3240 0.0 0.0 112720 968 pts/3 R+ 00:01 0:00 grep --color=autohttpd
爲了保險起見,能夠先建立一個php_errors.log再賦予 777 的權限
[root@xuexi-001 ~]# touch /tmp/php_errors.log ; chmod 777 /tmp/php_errors.log [root@xuexi-001 ~]# cat /tmp/php_errors.log [01-Jul-2018 15:57:43 UTC] PHP Warning: phpinfo() has been disabled for security reasons in /data/wwwroot/111.com/index.php on line 2
模擬一個錯誤演示:
[root@xuexi-001 ~]# vi /data/wwwroot/111.com/2.php <?php echo 1234.php; adfadgagagag [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful [root@xuexi-001 ~]# curl -A "a" -x127.0.0.1:80 http://111.com/2.php [root@xuexi-001 ~]# curl -A "a" -x127.0.0.1:80 http://111.com/2.php -I HTTP/1.0 500 Internal Server Error Date: Sun, 01 Jul 2018 16:10:23 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.36 X-Powered-By: PHP/5.6.36 Connection: close Content-Type: text/html; charset=UTF-8 // 出現狀態碼500,這說明咱們訪問的頁面是存在錯誤的,此時須要查看PHP的錯誤日誌來斷定錯誤緣由,以下: [root@xuexi-001 ~]# cat /tmp/php_errors.log [01-Jul-2018 15:57:43 UTC] PHP Warning: phpinfo() has been disabled for security reasons in /data/wwwroot/111.com/index.php on line 2 [01-Jul-2018 16:10:18 UTC] PHP Parse error: syntax error, unexpected 'php' (T_STRING), expecting ',' or ';' in /data/wwwroot/111.com/2.php on line 3 [01-Jul-2018 16:10:23 UTC] PHP Parse error: syntax error, unexpected 'php' (T_STRING), expecting ',' or ';' in /data/wwwroot/111.com/2.php on line 3