如何在Windows上使用Node.js运行Nginx? [英] How to run Nginx with Node.js on Windows?

查看:120
本文介绍了如何在Windows上使用Node.js运行Nginx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows上安装Nginx,并运行两个节点的应用程序.我该怎么办?

I want to install Nginx on Windows, and to run two node application. How can I do this?

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

I've tried to download Nginx 1.6.3, but I don't find something relevant about how to run on Windows. Just for Linux. I think there should be some modules for node.

任何建议都会有用!

推荐答案

我从来没有在Windows上运行Nginx,但是官方文档说:

I never run Nginx on Windows, but the official documentation says how: http://nginx.org/en/docs/windows.html.

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

To run two node applications with Nginx, it's necessary to create a proxy. This is an example of how to alter the nginx.conf file for this:

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;
        }
  }
}

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

In this case, there are two node applications, one running on port 3000 and an other on port 3001 - the Nginx works as a proxy.

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

在您的情况下,配置文件位于以下位置:C:\nginx_v1_6\conf\nginx.conf

In your case, the configuration file are localised in: C:\nginx_v1_6\conf\nginx.conf

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

Backup the default file and update the content with what I posted.

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

Finally, you can test the reverse-proxy through localhost (port 80 default) and localhost:81, if the nodes servers and Nginx server are running.

这篇关于如何在Windows上使用Node.js运行Nginx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆