Apache 與 lighthttpd:mime 類型的不同行為

Apache 與 lighthttpd:mime 類型的不同行為

我用 python 編寫了一個應用程序,一個適用於 Apple 裝置的自動 VPN 設定門戶網站。

讓我煩惱的是測試伺服器和生產伺服器之間的行為差異;前者是使用Apache,後者是使用lighthttpd

lighhttpd檔案.mobileconfig開啟並「執行」時,例如它會自動開啟 SysPrefs,而在 Apache 中則不會發生這種情況。

我已經注意到lighhtpd關於正確的定義要寬鬆得多Content-Type,但當前的問題是 Safari 會正確加載和“自動執行”.mobileconfig文件,lighthttpdApache.

更讓我煩惱的是,在兩台伺服器中我都正確定義了相應的內容mime.type,如下所示:

lighthttpd.conf

$HTTP["url"] =~ "\.mobileconfig$" {
    setenv.add-response-header = ( "Content-Disposition" => "attachment" )
    mimetype.assign = (".mobileconfig" => "application/x-apple-aspen-config",
                    "" => "application/octet-stream")
}

就像在 Apache 中一樣:

dovpn.conf(虛擬主機)

AddType application/x-apple-aspen-config .mobileconfig

差異的第一個線索其實似乎源自於add-response-header中的指令lighthttpd

在生成的 HTML 中,我有:

a download="profile.mobileconfig" href="../upload/8bd16b26-1473-4994-9803-8268a372cd0d.mobileconfig" type="application/octet-stream">Download automatic profile/a

我透過 Javascript 自動下載該文件

//If in Safari - download via virtual link click
if (window.downloadFile.isSafari) {
    //Creating new link node.
    var link = document.createElement('a');
    link.href = sUrl;
    if (link.download !== undefined) {
        //Set HTML5 download attribute. This will prevent file from opening if supported.
        var fileName = sUrl.substring(sUrl.lastIndexOf('/') + 1, sUrl.length);
        link.download = fileName;
    }
    //Dispatching click event.
    if (document.createEvent) {
        var e = document.createEvent('MouseEvents');
        e.initEvent('click', true, true);
        link.dispatchEvent(e);
        return true;
    }
}

產生頁面的內容也只有Content-Type:

Content-Type: text/html\n\n

在 Apache 和 lighthttpd 中都是如此。我透過網路嗅探,發現透過 .NET 對 Content-Type 沒有明顯的變更lighthttpd

我能用setenv.add-response-headerApache 複製類似的功能嗎?

我已經嘗試新增到 Apache 主機:

<Files "*.mobileconfig">
      Header set Content-Disposition attachment
</Files>

SetEnvIf Request_URI "\.mobileconfig$" change_header
Header set Content-Disposition attachment env=change_header

SetEnvIf Request_URI "\.mobileconfig$" change_header
Header always add "Content-Disposition" "attachment" env=change_header

<Files "*.mobileconfig">
    Header append Content-Disposition attachment
</Files>

我還嘗試在實際目錄中.htaccess使用以下命令建立檔案:

<IfModule mod_headers.c>
    <FilesMatch "\.mobileconfig$">
        ForceType application/octet-stream
        Header append Content-Disposition "attachment"
        Allow from all
    </FilesMatch>
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\.mobileconfig$">
        ForceType application/octet-stream
        Header add Content-Disposition "attachment"
        Allow from all
    </FilesMatch>
</IfModule>

除此之外,在這兩種情況下attachment,我還使用了"attachment".

請注意,mod_headers 在 Apache/Debian 9 中預設為活動狀態,並且這些替代方案都無效。

實際上,我只記得lighthttpd是使用 HTTP 和ApacheHTTPS。我使用 HTTPS 對 lighthttpd 進行了測試,它也可以透過 HTTPS 運行,而 Apache 則不能。

curl -k -I https://localhost/cgi-bin/vpn.pylighthttpd 伺服器的輸出:

HTTP/1.1 200 OK
Content type: text/html
Content-Length: 331
Date: Thu, 01 Jun 2017 09:03:26 GMT
Server: lighttpd/1.4.45

curl -k -I https://localhost/cgi-bin/vpn.pyApache 伺服器中的輸出:

HTTP/1.1 200 OK
Date: Thu, 01 Jun 2017 09:05:25 GMT
Server: Apache
Vary: Accept-Encoding
X-Frame-Options: sameorigin
Content-Type: text/html; charset=UTF-8

此外,在 Apache 中也是如此:

$curl -k -I https://localhost/download/xxx.mobileconfig
HTTP/1.1 200 OK
Date: Thu, 01 Jun 2017 09:13:35 GMT
Server: Apache
Last-Modified: Thu, 01 Jun 2017 03:08:57 GMT
ETag: "1f3b-550dd5b89d8df"
Accept-Ranges: bytes
Content-Length: 7995
X-Frame-Options: sameorigin
Content-Disposition: attachment
Content-Type: application/x-apple-aspen-config

使用Safari->開發->顯示Web檢查器->調試器->點擊主頁->複製為curl只返回“curl 'https://xxxx/cgi-bin/vpn.py貼上時“-Xnull”。

我也嘗試過禁用X-Frame-Options: "sameorigin",但沒有什麼區別(我知道這是一個不可能的事情)

答案1

看來使用該.htaccess文件解決了向標頭添加 Content-Disposition 的問題。

然而,複製功能的問題以及調試和測試中增加的複雜性——似乎有另一種解釋。

出於安全原因,最新的測試版和目前版本的 Sierra 更新檔案似乎都.mobileconfig從 Safari 的「安全性」檔案開啟清單中刪除。

我昨天(或前天)在工作時更新了 MacOS,今天在家裡更新了,我不再能夠.mobileconfig自動打開生產或預生產系統上的文件。

.mobileconfig我剛剛將我的 iPhone 更新到了 iOS 10.3.3 beta,這似乎也證實了蘋果將設定檔視為潛在危險的傾向。現在,當單擊此類文件時,您會看到一個新警告:

網站正在嘗試開啟“設定”以向您顯示設定檔。您想允許這樣做嗎?
忽略 - 允許

相關內容