當從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>
爲什麼不直接連接到'http:// localhost/path/to/file'? – Blender
@Blender,因爲它被設置爲具有'ServerName'的'VirtualHost',即在同一臺服務器上有多個站點。 – Petah