1.nginx服務(wù)器的安裝
sudo apt-get install nginx
2.nginx服務(wù)器的啟動(dòng)
sudo /etc/init.d/nginx start
3.多域名對(duì)應(yīng)不同的后臺(tái)服務(wù)器
在/etc/nginx/sites-enabled/ 目錄中刪除default配置文件
新建域名對(duì)應(yīng)的配置文件
比如test.youlunshidai.com
#通過(guò)upstream nodejs__upstream 可以配置多臺(tái)nodejs節(jié)點(diǎn),做負(fù)載均衡
upstream nodejs__upstream__test__youlunshidai {
server 127.0.0.1:8089; #服務(wù)器地址和端口號(hào)
#server 127.0.0.1:8088; #負(fù)載均衡服務(wù)器地址和端口號(hào)
keepalive 64; #設(shè)置存活時(shí)間照棋。如果不設(shè)置可能會(huì)產(chǎn)生大量的timewait
}
server {
listen 80;
server_name test.youlunshidai.com;
access_log /var/log/nginx/test_youlunshidai.log; #nginx日志文件
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass http://nodejs__upstream__test__youlunshidai; #反向代理轉(zhuǎn)發(fā) http://nodejs__upstream;
}
}
如果還有其他域名和后臺(tái)服務(wù)器由驹,在目錄下繼續(xù)新建對(duì)應(yīng)的域名配置文件即可
參考文章
Nginx反向代理Nodejs – log4js日志IP顯示錯(cuò)誤
http://www.dataguru.cn/article-3558-1.html