ubuntu用nginx綁定域名的示例:
1.準備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;
}
}
2.在終端運行以下命令即可:
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