Nginx is the best reverse proxy server.
Node. JS is... Okay, don't introduce it. Click here.
This section describes how to use nginx and node. js together.
Write helloworld. js first
VaR HTTP = require ('http'); http. createserver (function (request, response) {response. writehead (200, {'content-type': 'text/plain '}); response. end ('Hello world \ n ');}). listen (8000); console. log ('server running at http: // 127.0.0.1: 8000 /');
Then use the node helloworld. js command to enable it. In this way, the node. js program running on the local machine can be started up and occupies port 8000. You can modify it yourself.
Next, we will write a server in nginx vhost. conf.
Server {listen80; SERVER_NAME indexing. Me www. indexing. Me; Location/{proxy_pass http: // 127.0.0.1: 8000 ;}}
Set the website domain name, set the port to 80, and finally set proxy_pass to http: // 127.0.0.1: 8000, and pass all requests from the processing ing. Me: 80 to the nodejs program.
Restart nginx
Access the domain name and you will see helloworld.
Although node. js itself can be used as a server, for example, set port 80 in welcome. js.
However, when a host runs multiple websites and other websites use other servers, port 80 can be processed by proxy on other ports.