node.js - 使用 pm2 设置 NGINX 并在 Windows 10 上表达
问题描述
我现在正在探索代理、反向代理、负载平衡等环境。我使用节点 js、express、mongoose 等,并且我选择了网络服务器“NGINX”。我看到大部分视频都在 Linux 机器上,我应该从 Windows 10 切换到 Linux 吗?主要问题是:如何设置快速端口和pm2(用于负载平衡等)?我真的不知道如何在 app.listen() 中设置端口。理论上我有 3 个端口:8000-8001-8002。但是在 pm2 上我无法创建它们。在youtube上我见过这个命令,它不起作用......
pm2 start app.js -f --8000
pm2 start app.js -f --8001
pm2 start app.js -f --8002
它给了我这个错误:error: unknown option `--8000'
我想在本地主机上运行它,所以我没有任何域等。
在我写的 nginx.conf 中:
upstream notes {
server localhost:8000;
server localhost:8001;
server localhost:8002;
}
在服务器对象中:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root "C:\serversTest";
index index.html index.htm;
proxy_pass http://notes;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root "C:\serversTest";
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
我只想用 ngix 保护我的网站/网络应用程序并实现负载平衡和反向代理。(我在 Windows 10 顺便说一句)。
解决方案
推荐阅读
- excel - 如何根据 VBA 中的单元格内容设置元素 ID?
- c++ - 与 C++ 相比,Haskell 运行速度非常慢
- php - 日期和状态通过 PHP 中的 curl 提交空值
- monaco-editor - 如何覆盖编辑器服务
- r - 使用 for 循环在 R 中求解矩阵
- list - Prolog递归谓词结束后返回初始状态
- python - Nltk Tokenizing and add Bigrams by keep the sentence
- javascript - 如何防止 onClick 在 StencilJs 中禁用按钮
- python - 有没有办法使用 NetworkX 在有向图上生成分层输出?
- python - 在pynput lib中禁用自我按键检测(linux中的python 3)