ubuntu用nginx绑定域名的示例:
准备configuration,将以下的配置文件内容放入/etc/nginx/sites-available/node-app文件中,内容:
upstream node_server {
server 127.0.0.1:3000 fail_timeout=0;
server 127.0.0.1:5000 fail_timeout=0;
server 127.0.0.1:5001 fail_timeout=0;
}
server {
listen 80;
listen [::]:80 default_server;
index index.html index.htm;
server_name www.abc.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://node_server;
}
location /public/ {
root /opt/app;
}
}
在终端运行以下命令即可:
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/node-app /etc/nginx/sites-enabled/node-app
sudo /etc/init.d/nginx restart