javascript - 如何在 Windows 上使用 Node.js 运行 Nginx?

标签 javascript node.js nginx

我想在 Windows 上安装 Nginx,并运行两个 Node 应用程序。我该怎么做?

我尝试下载 Nginx 1.6.3,但没有找到与如何在 Windows 上运行相关的信息。仅适用于 Linux。我认为应该有一些 Node 模块。

任何建议都会有用!

最佳答案

我从未在 Windows 上运行 Nginx,但官方文档说明了如何运行:http://nginx.org/en/docs/windows.html .

要使用 Nginx 运行两个 Node 应用程序,必须创建一个代理。这是如何为此更改 nginx.conf 文件的示例:

worker_processes 1;

events {
        worker_connections 1024;
}
http {
        include mime.types;
        default_type application/octet-stream;
        sendfile on;
        keepalive_timeout 65;
        gzip on;
server {
        listen 80;
        server_name localhost;
        access_log C:\var\log\nginx\access.log;
                location ~ ^/(javascripts|stylesheets|images) {
                root C:\app1\public;
                expires max;
        }
        location / {
                proxy_pass http://localhost:3000;
        }
  }
server {
        listen 81;
        server_name localhost;
        access_log C:\var\log\nginx\access.log;
                location ~ ^/(javascripts|stylesheets|images) {
                root C:\app2\public;
                expires max;
        }
        location / {
                proxy_pass http://localhost:3001;
        }
  }
}

在这种情况下,有两个 Node 应用程序,一个在端口 3000 上运行,另一个在端口 3001 上运行 - Nginx 充当代理。

更多文档:https://www.nginx.com/blog/nginx-nodejs-websockets-socketio/ .

在您的例子中,配置文件本地化在:C:\nginx_v1_6\conf\nginx.conf

备份默认文件并用我发布的内容更新内容。

最后,如果 Node 服务器和 Nginx 服务器正在运行,您可以通过 localhost(默认端口 80)和 localhost:81 测试反向代理。

关于javascript - 如何在 Windows 上使用 Node.js 运行 Nginx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32460440/

相关文章:

angularjs - 从 AngularJs/ui-router 到 nginx 的带有尾部斜杠的 URL 访问不正确的资源

node.js - 在使用 Typescript 的 Mocha 测试中使用 Mockery 有技巧吗?

regex - Nginx 位置正则表达式,是否需要转义正斜杠?

javascript - 输入范围 slider 在 Chrome 中不起作用?在 Firefox 中工作

javascript - grails Remotefunction 多个参数

eclipse - Node.js 和 Eclipse 集成

mysql - 如何对 MySQL 进行基于条件的查询

php - 部署 Symfony 3.4.10 应用程序错误 : Allowed memory size exhausted by StreamHandler. php

javascript - NodeJS Promise 和 Symbol.species 的使用

javascript - 配置 sails 服务器以使用 html5Mode?