-
Nginx
Nginx是一款輕量級的Web服務器楔敌、反向代理服務器博脑,由于它的內(nèi)存占用少添履,啟動極快屁倔,高并發(fā)能力強,在互聯(lián)網(wǎng)項目中廣泛應用
-
Apache
阿帕奇這里不做過多介紹暮胧,Mac自帶锐借,詳情可去網(wǎng)上搜索
一问麸、Nginx
- 1.1、安裝(使用Homebrew)
$ brew install nginx
- 1.2钞翔、啟動
$ nginx
- 1.3严卖、驗證是否成功
http://localhost:8080
安裝成功
- 1.4、添加json文件
/usr/local/Cellar/nginx/1.15.12/html // 配置路徑布轿,??1.15.12是我安裝的版本號
添加前
添加置后
test.json內(nèi)容
- 1.5哮笆、配置Nginx
/usr/local/etc/nginx/nginx.conf.default // nginx.conf.default路徑
將以下代碼替換到nginx.conf.default到里面,
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_page 405 =200 http://$host$request_uri;
}
我用了一個叫 SubEthaEdit 的軟件編輯的驮捍,在AppStore里面下載即可疟呐。
- 1.6、展示
http://localhost:8080/test.json
展示
二东且、Apache
$ sudo apachectl start // 啟動
$ sudo apachectl stop // 關閉
$ sudo apachectl restart // 重啟
http://127.0.0.1 (或 http://localhost) // 查看是否啟動成功
啟動成功
/Library/WebServer/Documents // Web根目錄路徑
將指定文件放到Web根目錄下即可直接訪問启具,例:
http://localhost/test.json
http://本機IP/test.json
??????使用過后,記得關閉服務器珊泳,否則會一直消耗電腦內(nèi)存