Nginx+PM2+Node.js最簡單的配置

一個最簡單的反向代理配置方式

server {
  listen 80;
  server_name www.luckybing.top;

  location / {
     proxy_pass http://127.0.0.1:3000;
  }
}

使用PM2永動機啓動Node.js項目,再使用nginx作反向代理,簡直完美。node

由於node.js程序監聽的是服務器端口,使用nginx作反向代理,就能夠任意配置你的二級域名來訪問你的程序nginx

一個最簡單的負載均衡配置方式

upstream b.com { 
      ip_hash;
      server  192.168.5.150:80; 
      server  192.168.5.151:80;
      server  192.168.5.151:8080; 
} 

 一個最簡單的Https配置

server{
        listen 443 ssl;
        server_name xxx.xxx.com;
        ssl_certificate /root/certs/test.crt;
        ssl_certificate_key /root/certs/test.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 5m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
        location /{
                proxy_pass http://localhost:3000;
                proxy_set_header Host $host;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_read_timeout 86400;
        }
}

 

Nginx解決跨域問題

server{
        listen  80;
        server_name test.abc.com;

        location / {
            proxy_pass http://127.0.0.1:8080;

            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers Content-Type;
            add_header Access-Control-Allow-Methods POST;
            add_header Access-Control-Allow-Methods GET;
        }

}
相關文章
相關標籤/搜索