http://nginx.org/ html
http://nginx.org/en/linux_packages.html#stable linux
https://www.npmjs.com/package/json-server nginx
yum install openssl zlib pcre npm
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm json
yum install nginx vim
nginx –h centos
nginx api
nginx -s stop 瀏覽器
systemctl start nginx post
systemctl status nginx
systemctl enable nginx
systemctl stop nginx
瀏覽器查看
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
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/bbb/comments
502 Bad Gateway
解決方案
禁用selinux
setenforce 0
vi /etc/selinux/config
修改
SELINUX=disabled