参考

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

CentOS7安装Nginx实现API网关的更多相关文章

  1. linux(centos7) 安装nginx

    linux(centos7) 安装nginx 1.14(stable) 版本 Nginx配置文件常见结构的从外到内依次是「http」「server」「location」等等,缺省的继承关系是从外到内, ...

  2. 【Nginx安装】CentOS7安装Nginx及配置

    [Nginx安装]CentOS7安装Nginx及配置 2018年03月05日 11:07:21 阅读数:7073 Nginx是一款轻量级的网页服务器.反向代理服务器.相较于Apache.lighttp ...

  3. VMware虚拟机中的CentOS7安装Nginx后本机无法访问的解决办法

    VMware虚拟机中的CentOS7安装Nginx后本机无法访问的解决办法 在linux上安装nginx 请参考:Linux Centos7 安装 nginx 在虚拟机centos7上安装nginx之 ...

  4. CentOS7 安装Nginx+MySQL

    首先我们需要安装nginx的yum源 [root@AD ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-releas ...

  5. Centos7安装Nginx实战

    一.背景 最近在写一些自己的项目,用到了nginx,所以自己动手来在Centos7上安装nginx,以下是安装步骤. 二.基本概念以及应用场景 1.什么是nginx Nginx是一款使用C语言开发的高 ...

  6. centos7 安装nginx与配置

    第一步安装 使用Yum安装是推荐的方式,整体的流程非常的简单,也不容易出错,如果不需要什么特殊配置,建议使用Yum尽进行安装. 第一种安装方式,通过添加epel源 yum install epel-r ...

  7. centos7安装nginx的两种方法

    第一种方式:通过yum安装 直接通过 yum install nginx 肯定是不行的,因为yum没有nginx,所以首先把 nginx 的源加入 yum 中 运行下面的命令: 1.将nginx放到y ...

  8. Centos7安装nginx后提示“Welcome to nginx on Fedora!”,conf.d目录下无default.conf文件

    问题描述 在腾讯云centos7上安装nginx sudo yum install nginx 打开默认网页显示 Welcome to nginx on Fedora! 且 /etc/nginx/co ...

  9. Nginx 实现API 网关

    1,网关 网关(Gateway)就是一个网络连接到另一个网络的“关口”. 在Nginx 配置负载均衡之后,可以进入到网关,在网关决定进入到哪个真实的web 服务器. 2,将Ngnix 配置 API 网 ...

随机推荐

  1. php二维数组的某一字段 做分组统计

    $country=array_column($order,'country');$countryGP=array_count_values($country);对二维数组的某一字段 做分组统计

  2. Python——用socket和线程实现全双工收发数据

    用socket和线程实现全双工收发数据 1.基础知识 Socket(套接字) 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket.由此知道套接字是全双工的. 线程 ...

  3. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  4. 11.Find All Numbers Disappeared in an Array(找出数组中缺失的数)

    Level:   Easy 题目描述: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements ...

  5. Redis 工具类 java 实现的redis 工具类

    最近了解了一下非关系型数据库 redis 会使用简单的命令 在自己本地电脑 使用时必须先启动服务器端 在启动客户端 redis 简介 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内 ...

  6. 去除IDEA报黄色/灰色的重复代码的下划波浪线

    解决方法: File---->Settings

  7. [Android UI]View滑动方式总结

    一.前言 在上一篇文章,介绍了View的坐标等基础知识,有了基础知识后,对下面内容的理解也将会容易很多.那么本文介绍的是View滑动的几种方式,这对于View来说,也是需要重要掌握的内容,因为用户无时 ...

  8. POJ 1000 A+B

    #include <stdio.h> int main() { int a,b; scanf("%d %d",&a, &b); printf(" ...

  9. P4289 [HAOI2008]移动玩具

    传送门 广搜 4*4 的方阵只有 0 和 1 显然可以状态压缩 (如样例的开始状态压缩后就是1111000011100010) 为了加快速度用了双向广搜(顺便学了一下双向广搜) 双向广搜顾名思义 就是 ...

  10. PHP HTTP的PUT,DELETE的使用

    GET操作是安全的.所谓安全是指不管进行多少次操作,资源的状态都不会改变.比如我用GET浏览文章,不管 浏览多少次,那篇文章还在那,没有变化.当然,你可能说每浏览一次文章,文章的浏览数就加一,这不也改 ...