惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 抱影无眠

CentOS7中添加新硬盘 CentOS7 安装oracle 客户端 CentOS7安装RabbitMQ CentOS7安装MongoDB3.6企业版 CentOS 搭建Redis4 环境 Nginx 在Windows下搭建静态Web服务 DevExtreme 搭建Node.js开发环境 MongoDB 搭建Node.js开发环境 MongoDB Windows环境搭建 Oracle 搭建Node.js开发环境 搭建Node.js Redis开发环境 Redis Windows环境搭建 使用PM2守护Node.js应用 Windows下使用nvm管理多个Node.js 版本 vscode 插件todo-highlight Ionic 解决gradle下载慢的问题 Cmder 简明使用说明 Ionic2 开发环境搭建 Ionic2集成DevExtreme
CentOS7安装Nginx实现API网关
抱影无眠 · 2018-07-24 · via 博客园 - 抱影无眠

参考

http://nginx.org/

http://nginx.org/en/linux_packages.html#stable

https://www.npmjs.com/package/json-server

安装

yum install openssl zlib pcre

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install nginx

命令行启动

nginx –h

nginx

nginx -s stop

服务模式

systemctl start nginx

systemctl status nginx

systemctl enable nginx

systemctl stop nginx

浏览器查看

http://hostname

安装json-server模拟API服务

npm install json-server –g

echo "json-server a.json -H 192.168.1.6 -p 3000" > a-server.sh

echo "json-server b.json -H 192.168.1.6 -p 3001" > b-server.sh

chmod a+x a-server.sh b-server.sh

vi a.json

vi b.json

a.json 参考代码

{

"posts": [

{ "id": 1, "title": "json-server", "author": "typicode" }

]

}

b.json参考代码

{

"comments": [

{ "id": 1, "body": "some comment", "postId": 1 }

]

}

启动模拟api服务

./a-server.sh

./b-server.sh

配置Nginx为API网关

vim /etc/nginx/conf.d/a.conf

a.conf参考代码

server {

listen 80;

server_name 192.168.1.6;

location / {

proxy_pass http://192.168.1.6:3000/;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $host;

}

location /aaa/ {

proxy_pass http://192.168.1.6:3000/;

}

location /bbb/ {

proxy_pass http://192.168.1.6:3001/;

}

}

systemctl restart nginx

浏览器查看

http://192.168.1.6/aaa/posts

http://192.168.1.6/bbb/comments

错误

502 Bad Gateway

解决方案

禁用selinux

setenforce 0

vi /etc/selinux/config

修改

SELINUX=disabled