2013-05-26 16 views
1

當從PhantomJS創建到localhost上承載的域的連接時,客戶端IP將被檢測爲服務器外部IP。Apache/PhantomJS將localhost視爲外部IP

Apache配置爲擁有htpasswd,並且它被設置爲允許本地連接繞過它。但在錯誤日誌中我得到:

[Mon May 27 10:23:31 2013] [error] [client 123.215.64.94] user not found: /path/to/file 

123.215.64.94是服務器的外部IP地址之一。

的PhatomJS腳本是:

var page = require('webpage').create(); 
page.open('http://mysite.com/path/to/file', function() { 
    page.render('output.png'); 
    phantom.exit(); 
}); 

那麼,如何配置Apache繞過htpasswd的(而不必把服務器的Apache配置外部IP地址)?

Apache的配置是:

<VirtualHost *:80> 
    ServerName mysite.com 
    DocumentRoot /home/www-mysite/public 
    <Directory /home/www-mysite/public> 
     Options -Indexes FollowSymLinks 
     AllowOverride all 
     AuthUserFile /home/www-data/.htpasswd 
     AuthName "Password Protected" 
     AuthType Basic 
     Order Deny,Allow 
     Satisfy any 
     Deny from all 
     Require valid-user 
     Allow from 127.0.0.1 ::1 
    </Directory> 
</VirtualHost> 
+0

爲什麼不直接連接到'http:// localhost/path/to/file'? – Blender

+0

@Blender,因爲它被設置爲具有'ServerName'的'VirtualHost',即在同一臺服務器上有多個站點。 – Petah

回答

1

我認爲這可以作爲Apache,而不是一個PhantomJS,問題來處理。出於所有意圖和目的,「123.215.64.94」和「127.0.0.1」是同一個人。只有同一臺機器上的某個人才能從「123.215.64.94」訪問。

所以在你的Apache配置,你可以改變Allow from 127.0.0.1 ::1Allow from 127.0.0.1 ::1 123.215.64.94

當然,這是如果服務器配置多臺服務器上使用的壞主意;或者它是短命的雲實例,並且每次都獲取新的IP地址。在這種情況下,在Apache配置中使用環境變量將更加穩定。

+0

是的,不理想,我想到了這一點。可能是唯一的方法。我也想過把域名添加到主機文件並將其重定向到「127.0.0.1」。 – Petah