您的位置:首页 > 其它

简单的API服务器搭建

2015-12-02 10:20 183 查看
首先需要下载一个Nginx 高性能的HTTP和反向代理服务器

安装 brew install Nginx

Step1: 配置conf文件

Mac上默认配置文件:/usr/local/etc/nginx/nginx.conf

server {

listen 8080;

server_name localhost;

#charset utf-8;

#access_log logs/host.access.log main;

location / {

add_header Content-Type "application/json";

root html;

index index.html index.htm;

}

}

Step2: 添加测试Json文件

Mac上默认路径:/usr/local/Cellar/nginx/1.8.0/

可将文件夹,当成Http请求的路径。

如文件路径为:/usr/local/Cellar/nginx/1.8.0/html/json/user.json

则访问地址为:http://localhost:8080/json/user.json

开启nginx:sudo nginx

关闭:pkill -9 nginx

重新加载:nginx -s reload
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: