https://github.com/wmui/web-deploy/blob/master/nginx-an-zhuang-pei-zhi.md
Nginx安裝
sudo apt-get install nginx
通過(guò)nginx -v查看版本號(hào)
代理設(shè)置
打開(kāi)/etc/nginx/conf.d/文件夾拴清,創(chuàng)建配置文件hello-8081.conf,內(nèi)容如下:
# 這里是代理端口號(hào) hello和8081根據(jù)你的情況配置
upstream hello {
server 127.0.0.1:8081;
}
server {
listen 80;
# 域名配置
server_namehello.example.com;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Nginx-proxy true;
# 不要忘記這個(gè)模塊的配置
proxy_passhttp://hello;
proxy_redirect off;
}
}
解釋?zhuān)号渲梦募?lèi)型必須以.conf結(jié)尾诅福,文件名可自定義,為了方便記憶苦锨,遂以項(xiàng)目名加端口號(hào)的方式命名谦趣。
完成配置后玉控,執(zhí)行sudo nginx -t查看是否配置成功
sudo service nginx start?? //啟動(dòng)服務(wù)sudo nginx -s reload重啟服務(wù)
如果啟動(dòng)失敗飞主,可能是防火墻導(dǎo)致的,關(guān)閉防火墻
//臨時(shí)關(guān)閉
service iptables stop
//禁止開(kāi)機(jī)啟動(dòng)
chkconfig iptables off
域名解析
解析你的域名到你的服務(wù)器ip高诺,這樣就可以通過(guò)訪問(wèn)hello.example.com代理服務(wù)器的8081端口,Nginx在這里的作用就是讓你可以在一臺(tái)服務(wù)器跑多個(gè)Node項(xiàng)目碾篡。