1. 安裝Homebrew
2. 安裝Nginx
3. 啟動Nginx
4. 配置JSON文件
5. 配置Nginx
6. 展現(xiàn)成果
1.安裝Homebrew
打開終端蝇率,輸入:
ruby?-e?"$(curl?-fsSL?https://raw.githubusercontent.com/Homebrew/install/master/install)"?
跟著步驟走。終端都有提示桦山。
2.依賴Homebrew安裝Nginx
依舊在終端中
brew?install?nginx??
3.啟動Nginx
依舊在終端里耳贬,輸入
nginx??
回車就行了踏堡。別驚訝,就這么簡單咒劲。?
怎樣驗證Nginx能用了呢顷蟆。你在瀏覽器里輸入localhost:8080,回車腐魂,出現(xiàn)以下畫面帐偎,說明成功。
4.配置JSON文件 那配置文件是在
?/usr/local/Cellar/nginx/1.8.0/html/?
這個目錄下會默認(rèn)有50x.html和index.html兩個文件蛔屹。你再新加一個json文件削樊,取個名字叫oscar.json,里面隨便寫些字典數(shù)組兔毒,保存漫贞。
5.配置Nginx
安裝完之后,默認(rèn)路徑是
/usr/local/etc/??
這個文件下會有一個nginx文件夾和一個openssl的文件夾育叁。
點開nginx文件夾迅脐,里面會有個
nginx.conf.default??
的文件,記住豪嗽,不要看錯了谴蔑,這里面的名字很相像。用文本編輯器打開昵骤,里面默認(rèn)是有內(nèi)容的树碱,可以看看。將以下內(nèi)容粘貼進(jìn)去变秦。
server?{? ? ? ? ??
????listen???????8080;??????
????server_name??localhost;???????????
????#access_log??logs/host.access.log??main;???
????location?~*?{???????????????
????????add_header?Content-Type?"application/json";??
????????root???html;???????????????
????????if?(!-f?$request_filename)?{???????????????????
????????????rewrite?^/(.*)??/$1.json?last;??
????????}???????????????
?????????index??index.php?index.html?index.htm;??
????}???????????
error_page405?=200?http://$host$request_uri;???????
}??
6.展現(xiàn)成果
如果你新加的json文件叫oscar.json成榜,目錄是在剛剛說的
/usr/local/Cellar/nginx/1.8.0/html/oscar.json??
那么你在瀏覽器里輸入(前面的localhost可以換成自己的IP地址 這樣別人都可以訪問了?)
localhost:8080/oscar.json??
看看你的成果吧!
如果你的頁面有你配置的JSON文件蹦玫,那么恭喜你赎婚。別人如果想訪問你的資源刘绣,保證你兩在同一個局域網(wǎng)內(nèi),然后把你的ip地址替換localhost挣输,再看看你朋友的電腦的頁面吧纬凤。
通過brew 安裝install 后
sudo?cp?/usr/local/opt/nginx/*.plist??/Library/LaunchDaemons??
sudo?launchctl?load?-w?/Library/LaunchDaemons/homebrew.mxcl.nginx.plist??
即可。
本文出自:【snowrain1108的博客】:http://blog.csdn.net/snowrain1108/article/details/50072057撩嚼;
本文參考自:?http://blog.csdn.net/qq_22383951/article/details/53019034