欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nginx設(shè)置為Node.js的前端服務(wù)器方法總結(jié)

 更新時間:2019年03月27日 08:37:54   投稿:laozhang  
在本篇文章中小編給大家分享了關(guān)于Nginx設(shè)置為Node.js的前端服務(wù)器的方法和實例,需要的朋友們學(xué)習(xí)下。

1、安裝node.js

首先安裝node.js安裝所需的軟件包,并在啟動板上添加可用的nodejs的PPA。之后使用以下命令安裝nodejs。

$ sudo apt-get install python-software-properties python g++ make

$ sudo add-apt-repository ppa:chris-lea/node.js

$ sudo apt-get update

$ sudo apt-get install nodejs

2、安裝nginx

現(xiàn)在使用apt get安裝nginx web服務(wù)器。nginx在默認(rèn)存儲庫下可用。

$ sudo apt-get install nginx

3、創(chuàng)建測試node服務(wù)器

現(xiàn)在創(chuàng)建一個測試node服務(wù)器應(yīng)用程序,并在主機127.0.0.1的端口3000上運行它。要創(chuàng)建node服務(wù)器,請創(chuàng)建文件~/myapp/myapp.js。

$ cd ~/MyApp/

$ vi myapp.js

并在javascript文件中添加以下內(nèi)容。

var http = require('http');

 

http.createServer(function (req, res) {

  res.writeHead(200, {'Content-Type': 'text/plain'});

  res.end('Hello Worldn');

}).listen(3000, "127.0.0.1");

console.log('Server running at http://127.0.0.1:3000/');

現(xiàn)在使用以下命令在后臺啟動nodejs

$ node myapp.js &

在瀏覽器中訪問。

輸出:Hello Word

4、配置NGNIX

使用node.js啟動演示服務(wù)器后,現(xiàn)在開始使用Nginx進行配置。在/etc/nginx/conf.d/目錄下為域創(chuàng)建虛擬主機配置文件。

$ sudo vim /etc/nginx/conf.d/example.com.conf

并添加以下內(nèi)容。

upstream myapp {

  server 127.0.0.1:3000;

  keepalive 8;

}

 

# the nginx server instance

server {

  listen 0.0.0.0:80;

  server_name example.com www.example.com;

  access_log /var/log/nginx/example.com.log;

 

  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_pass http://myapp/;

   proxy_redirect off;

  }

 }

完成所有配置后,讓我們使用以下命令重新啟動nginx Web服務(wù)器。

$ sudo /etc/init.d/nginx restart

5、驗證安裝程序

現(xiàn)在使用域名訪問你的服務(wù)器,你將在http://127.0.0.1:3000/上看到相同的頁面。

輸出為Hello Word

相關(guān)文章

最新評論