一灶似、Mac OS X 啟用 web 服務(wù)器
Mac OS X 自帶了Apache環(huán)境睬魂,我們只需要啟動(dòng)它就行了幻林,可以通過在終端(terminal)輸入 httpd -v
來查看Apache的版本信息:
$ httpd -v
Server version: Apache/2.4.18 (Unix)
Server built: Feb 20 2016 20:03:19
啟動(dòng)Apache
在終端輸入 sudo apachectl start
就可以啟動(dòng)Apache贞盯。
啟動(dòng)后,在瀏覽器中輸入 http://127.0.0.1
或http://localhost
如果看到 It Works! 頁面:
Apache 就啟動(dòng)成功了沪饺,站點(diǎn)的根目錄為系統(tǒng)級根目錄:
/Library/WebServer/Documents
停止Apache:
sudo apachectl stop
重啟Apache:
sudo apachectl restart
二邻悬、開啟 HTTPS 服務(wù)
iOS 7.1 以上的設(shè)備部署OTA環(huán)境必須使用HTTPS,可以配置Apache開啟HTTPS服務(wù)随闽。
創(chuàng)建自簽名證書
-
首先創(chuàng)建一個(gè)ssl目錄用來存放證書:
$ cd /etc/apache2/ $ sudo mkdir ssl $ cd ssl
-
創(chuàng)建主機(jī)密鑰:
$ sudo ssh-keygen -f 192.168.3.112.key Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in 192.168.3.112.key. Your public key has been saved in 192.168.3.112.key.pub. The key fingerprint is: SHA256:bNX90ww2g2GCh38Q/h68JnazkZYtnbkMEb1G5E51QWw root@XXdeiMac.local The key's randomart image is: +---[RSA 2048]----+ | oo.o +o+| | o.o+ B E.| | oo.+ % | | . ..o.* B.| | S .= +.+| | . . X o.| | o & = | | . = B . | | . o | +----[SHA256]-----+ $
執(zhí)行
sudo ssh-keygen -f 192.168.2.112.key
命令父丰,會(huì)被要求提供一個(gè)密碼用于主機(jī)密鑰,可以選擇任何的密碼或直接留空。其中192.168.2.112
是指Mac的內(nèi)網(wǎng)地址蛾扇,下同攘烛。也可以使用下面的命令創(chuàng)建密鑰:
$ sudo openssl genrsa -out 192.168.2.112.key 2048 Generating RSA private key, 2048 bit long modulus ....+++ ....+++ e is 65537 (0x10001) $
-
創(chuàng)建簽署申請:
$ sudo openssl req -new -key 192.168.2.112.key -out 192.168.2.112.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:192.168.2.112 Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: $
執(zhí)行 sudo openssl req -new -key 192.168.2.112.key -out 192.168.2.112.csr
命令后,系統(tǒng)會(huì)提示輸入各項(xiàng)信息镀首,由于這是自簽名的證書坟漱,除了 Common Name (e.g. server FQDN or YOUR name) []: FQDN( fully qualified domain name)必須是服務(wù)器域名或 IP 外,其他都不重要更哄,可以隨意填寫或一路回車芋齿。
-
創(chuàng)建SSL證書:
在生產(chǎn)環(huán)境中,我們需要提交證書申請(CSR)文件給證書頒發(fā)機(jī)構(gòu)成翩,由證書頒發(fā)機(jī)構(gòu)提供SSL證書觅捆。
$ sudo openssl x509 -req -days 365 -in 192.168.2.112.csr -signkey 192.168.2.112.key -out 192.168.2.112.crt Signature ok subject=/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=192.168.2.112 Getting Private key $
我們也可以直接通過以下的命令創(chuàng)建證書:
$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout 192.168.2.112.key -out 192.168.2.112.crt
-
創(chuàng)建NOPASS密鑰:
$ sudo openssl rsa -in 192.168.2.112.key -out 192.168.2.112.nopass.key
到目前為止SSL目錄下已經(jīng)創(chuàng)建了下面一些文件,這些文件將在后面被用到:
$ ls -l -rw-r--r-- 1 root wheel 1180 10 22 13:08 192.168.2.112.crt -rw-r--r-- 1 root wheel 993 10 22 11:58 192.168.2.112.csr -rw------- 1 root wheel 1679 10 22 11:44 192.168.2.112.key -rw-r--r-- 1 root wheel 408 10 22 11:44 192.168.2.112.key.pub -rw-r--r-- 1 root wheel 1679 10 22 13:19 192.168.2.112.nopass.key
配置 SSL
-
編輯
/etc/apache2/httpd.conf
文件麻敌,刪除下列代碼前的注釋符號(hào) #:LoadModule ssl_module libexec/apache2/mod_ssl.so Include /private/etc/apache2/extra/httpd-ssl.conf
-
編輯
/etc/apache2/extra/httpd-ssl.conf
文件栅炒,添加<VirtualHost>
,httpd-ssl.conf
中已經(jīng)有一條<VirtualHost>
記錄术羔,我們將其注釋掉赢赊,新建一條:<VirtualHost *:443> #General setup for the virtual host DocumentRoot "/Library/WebServer/Documents" ServerName 192.168.2.112 #SSL Engine Switch: SSLEngine on #Server Certificate: SSLCertificateFile "/etc/apache2/ssl/192.168.2.112.crt" #Server Private Key: SSLCertificateKeyFile "/etc/apache2/ssl/192.168.2.112.key" #SSL Engine Options: <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory "/Library/WebServer/CGI-Executables"> SSLOptions +StdEnvVars </Directory> </VirtualHost>
檢查配置文件并重啟 Apache
命令行輸入 $ sudo apachectl -t
,可能會(huì)提示:
AH00526: Syntax error on line 92 of /private/etc/apache2/extra/httpd-ssl.conf:
SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).
根據(jù)提示级历,編輯 /etc/apache2/httpd.conf
文件释移,刪除下列這些代碼前的注釋符號(hào) #
LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so
再次測試,顯示 Syntax OK:
$ sudo apachectl -t
Syntax OK
說明測試通過寥殖,重啟 Apache:
$ sudo apachectl restart
此時(shí)玩讳,就可以使用 HTTPS 訪問本地服務(wù)了,在瀏覽器中輸入 https://192.168.2.112/ 扛禽。
三锋边、使用企業(yè)級證書打包生成ipa及plist文件:
打包具體步驟這里就不詳述了皱坛,主要說一點(diǎn)编曼,打包最后一步中,填寫如下manifet.plist文件:
其中剩辟,各項(xiàng)都必須填寫掐场,URL是指相應(yīng)文件在web服務(wù)器中的URL,比如ipa文件贩猎,如果直接放在服務(wù)器主目錄下熊户,則App URL為 https://192.168.2.112/TESTAPP.ipa 。
各項(xiàng)都填寫好吭服,Export ipa成功后嚷堡,需要將 ipa、兩個(gè)image文件以及manifest.plist文件放到剛剛填寫的URL對應(yīng)的服務(wù)器目錄下。
四蝌戒、為web服務(wù)器生成首頁文件:index.html :
-
創(chuàng)建一個(gè)如下內(nèi)容的index.html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>應(yīng)用名字</title> </head> <body> <h1 style="font-size:40pt">iOS應(yīng)用OTA安裝<h1/> <h1 style="font-size:40pt"> <a title="iPhone" href="itms-services://?action=download-manifest&url=https://192.168.3.112/manifest.plist">點(diǎn)擊安裝</a> <h1/> <a title="iPhone" >ssl 證書安裝</a> <h1/> </body> </html>
其中串塑,
https://192.168.3.112/manifest.plist
指向打包生成的plist文件,http://192.168.3.112/192.168.3.112.crt
指向服務(wù)器中的CA證書北苟,也就是上述生成crt證書桩匪,因此,需要將上述生成的crt證書copy到web服務(wù)器目錄下友鼻。 將index.html放到web服務(wù)器主目錄下傻昙。
-
為了使web服務(wù)器能夠正常的傳輸plist及ipa文件,需要配置 Web 服務(wù)器彩扔,設(shè)定服務(wù)器 MIME 類型,即編輯
/etc/apache2/mime.types
文件妆档,添加如下兩種類型:application/octet-stream ipa text/xml plist
打開iPhone或者iPad中的瀏覽器,輸入web服務(wù)器地址:
https://192.168.2.112
借杰,如果出現(xiàn)如下內(nèi)容过吻,說明服務(wù)器已搭建成功:
先點(diǎn)擊ssl安裝證書
安裝相應(yīng)的CA證書,然后在點(diǎn)擊點(diǎn)擊安裝
進(jìn)行app安裝蔗衡。
五纤虽、安裝過程中可能遇到的問題及解決方案:
-
顯示下載失敗:
官方文檔中指出三種原因:
1)請確定應(yīng)用已正確進(jìn)行簽名绞惦。測試方法是使用 Apple Configurator 2 將它安裝到設(shè)備上逼纸,然后查看是否發(fā)生錯(cuò)誤。
2)請確定清單文件的鏈接是否正確济蝉,清單文件是否可供網(wǎng)絡(luò)用戶訪問杰刽。
3)請確定 .ipa 文件(在清單文件中)的 URL 是否正確,并且該 .ipa 文件是否可供網(wǎng)絡(luò)用戶通過 HTTPS 訪問王滤。
-
無法連接到“192.168.3.112”:
1)是否先下載了CA證書
2)CA證書中的服務(wù)器與
<a href="itms-services://?action=download-manifest&url=https://192.168.3.112/manifest.plist">Install App</a>
中的url是否匹配贺嫂,因?yàn)?code>點(diǎn)擊下載時(shí),iOS會(huì)使用下載下來的CA證書進(jìn)行驗(yàn)證雁乡,只有驗(yàn)證通過才能進(jìn)行下載安裝第喳。比如我就出現(xiàn)這個(gè)問題,CA證書中服務(wù)器是自己定義的域名踱稍,而manifest
中的url用的是IP地址曲饱。 -
無法下載應(yīng)用程序 此時(shí)無法安裝“XXX”:
1)我出現(xiàn)這個(gè)問題的原因是,沒有提供Xcode打包時(shí)珠月,manifest.plist中指定的兩個(gè)image扩淀,將兩個(gè)相應(yīng)的image放到web服務(wù)器中后就可以下載安裝了。
參考文章:
http://help.apple.com/deployment/ios/#/apda0e3426d7
http://www.reibang.com/p/35ca63ec0d8e
http://www.reibang.com/p/d006a34a343f