Nginx代理轉發
目錄
Server
cnpm i -g express-generator pm2
Server1
express Server1
# cd Server1
cnpm i
sed -i 's/3000/5001/g' ./bin/www
tee ./routes/index.js <<-'EOF'
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.send(JSON.stringify({ msg: 'Server1' }));
});
module.exports = router;
EOF
MacOS下sed修改檔案明瞭和Ubuntu不同: sed -i "" 's/3000/5001/g' ./bin/www
pm2 start bin/www
Server2
express Server2
# cd Server2
cnpm i
sed -i 's/3000/5002/g' ./bin/www
tee ./routes/index.js <<-'EOF'
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.send(JSON.stringify({ msg: 'Server2' }));
});
module.exports = router;
EOF
MacOS下sed修改檔案明瞭和Ubuntu不同: sed -i "" 's/3000/5002/g' ./bin/www
pm2 start bin/www
nginx
sudo vim /etc/nginx/conf.d/proxy.conf
server {
listen 80;
server_name test.com;
location / {
proxy_pass http://localhost:5001;
if ($http_ZeahoRelease = "1.7.0") {
proxy_pass http://localhost:5002;
}
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
sudo nginx -t
sudo nginx -s reload
# hosts
sudo sh -c "echo '47.75.67.227 test.com' >> /etc/hosts"
Test
curl test.com # 返回"Server1"
curl --header "ZeahoRelease:1.7.0" test.com # 返回"Server2"
參考
相關文章
- Nginx配置正向代理支援HTTP和HTTPS轉發NginxHTTP
- nginx 代理轉發 傳遞真實 ip 地址Nginx
- nginx配置轉發Nginx
- nginx 轉發 redisNginxRedis
- 利用nginx的stream模組實現內網埠的轉發代理Nginx內網
- nginx正向代理、反向代理Nginx
- nginx轉發swoole以及nginx負載Nginx負載
- nginx代理配置Nginx
- Nginx反向代理Nginx
- nginx 代理 minioNginx
- nginx 反向代理Nginx
- nginx代理websocketNginxWeb
- nginx 代理phpNginxPHP
- nginx 代理websocketNginxWeb
- Nginx 根據不同的域名來代理轉發內部主機-HTTP和HTTPSNginxHTTP
- nginx 轉發 rtmp 直播流Nginx
- Nginx正向代理和反向代理配置Nginx
- Nginx之路--配置正向代理、反向代理Nginx
- Nginx伺服器配置---反向代理服務時proxy_pass的轉發規則Nginx伺服器
- Nginx代理服務Nginx
- Nginx 代理快取Nginx快取
- Nginx 配置反向代理Nginx
- Nginx 配置:反向代理Nginx
- Gulp的代理轉發外掛
- Nginx安裝與代理Nginx
- nginx 做正向代理配置Nginx
- 010.Nginx正反代理Nginx
- Nginx服務系列——代理Nginx
- nginx代理304問題Nginx
- Nginx四層反向代理Nginx
- tomcat 配置nginx 反向代理TomcatNginx
- nginx 反向代理 swoole 使用Nginx
- centos上nginx轉發tcp請求CentOSNginxTCP
- 內網穿透之流量代理轉發內網穿透
- 內網滲透-隧道代理轉發內網
- 內網入口——代理搭建&埠轉發內網
- Nginx專題(1):Nginx之反向代理及配置Nginx
- Nginx 學習系列(一) ------------- 正向代理與反向代理Nginx