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 代理轉發 傳遞真實 ip 地址Nginx
- nginx 反向代理做域名轉發簡單配置Nginx
- Nginx配置正向代理支援HTTP和HTTPS轉發NginxHTTP
- nginx做代理IP埠轉發的安裝和部署配置Nginx
- 利用nginx的stream模組實現內網埠的轉發代理Nginx內網
- nginx正向代理、反向代理Nginx
- Nginx反向代理Nginx
- nginx代理配置Nginx
- nginx 代理websocketNginxWeb
- nginx代理websocketNginxWeb
- nginx 代理phpNginxPHP
- nginx 反向代理Nginx
- nginx配置轉發Nginx
- nginx 轉發 redisNginxRedis
- Nginx之路--配置正向代理、反向代理Nginx
- Nginx正向代理和反向代理配置Nginx
- nginx轉發swoole以及nginx負載Nginx負載
- Nginx 代理快取Nginx快取
- Nginx代理服務Nginx
- Nginx 配置:反向代理Nginx
- Nginx 配置反向代理Nginx
- [Nginx] TCP 反向代理NginxTCP
- Nginx實現代理Nginx
- nginx代理引數Nginx
- Nginx 代理設定Nginx
- Nginx 反向代理 websocketNginxWeb
- nginx 代理 minioNginx
- [轉]反向代理過程與Nginx特點詳解Nginx
- Nginx 根據不同的域名來代理轉發內部主機-HTTP和HTTPSNginxHTTP
- Nginx伺服器配置---反向代理服務時proxy_pass的轉發規則Nginx伺服器
- Nginx禁止特定使用者代理(UserAgents)訪問(轉)Nginx
- nginx 做正向代理配置Nginx
- Nginx安裝與代理Nginx
- Nginx服務系列——代理Nginx
- nginx 反向代理 swoole 使用Nginx
- Nginx多層代理配置Nginx
- nginx 反向代理設定Nginx
- Nginx四層反向代理Nginx