-
Nginx
Nginx是一款輕量級(jí)的Web服務(wù)器、反向代理服務(wù)器,由于它的內(nèi)存占用少,啟動(dòng)極快,高并發(fā)能力強(qiáng),在互聯(lián)網(wǎng)項(xiàng)目中廣泛應(yīng)用
-
Apache
阿帕奇這里不做過多介紹,Mac自帶,詳情可去網(wǎng)上搜索
一、Nginx
- 1.1、安裝(使用Homebrew)
$ brew install nginx
- 1.2、啟動(dòng)
$ nginx
- 1.3、驗(yàn)證是否成功
http://localhost:8080

安裝成功
- 1.4、添加json文件
/usr/local/Cellar/nginx/1.15.12/html // 配置路徑,??1.15.12是我安裝的版本號(hào)

添加前

添加置后

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;
}
我用了一個(gè)叫 SubEthaEdit 的軟件編輯的,在AppStore里面下載即可。
- 1.6、展示
http://localhost:8080/test.json

展示
二、Apache
$ sudo apachectl start // 啟動(dòng)
$ sudo apachectl stop // 關(guān)閉
$ sudo apachectl restart // 重啟
http://127.0.0.1 (或 http://localhost) // 查看是否啟動(dòng)成功

啟動(dòng)成功
/Library/WebServer/Documents // Web根目錄路徑
將指定文件放到Web根目錄下即可直接訪問,例:
http://localhost/test.json
http://本機(jī)IP/test.json
??????使用過后,記得關(guān)閉服務(wù)器,否則會(huì)一直消耗電腦內(nèi)存