首页 > 解决方案 > 使用 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 顺便说一句)。

标签: node.jsexpresssecuritynginxreverse-proxy

解决方案


推荐阅读