我想在 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/