Nginx - 多应用

Nginx - Multiple application

不久前,我使用 Nginx 和 Supervisord 在 Centos7 上部署了一个 Meteor 应用程序。它工作正常,这里是配置文件:

nginx.conf:

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        proxy_pass http://localhost:3003/;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
    }
}

supervisord.conf:

[program:monitoring]
command=node main.js              ; the program (relative uses PATH, can take args)
directory=/home/blu16103@teamlog.intra/bundle
process_name=%(program_name)s ; process_name expr (default %(program_name)s)
numprocs=1                    ; number of processes copies to start (def 1)
autostart=true                ; start at supervisord start (default: true)
autorestart=unexpected        ; whether/when to restart (default: unexpected)
;user=app_user                   ; setuid to this UNIX account to run the program
redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile=/var/log/meteor.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
stderr_logfile=/var/log/meteor_err.log        ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)
;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
environment=MONGO_URL="mongodb://<username>:<password>@localhost:27017/monitoring"  ; process environment additions (def no adds)

问题

今天我想在这台服务器上放另一个应用程序。为此,我尝试更改我的第一个流星应用程序的位置,正如许多教程所说:

location /monitoring/ {
    proxy_pass http://localhost:3003/;
    ...
}

但是我得到一个 50x 错误:

> [error] 23284#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 10.20.3.135, server: _, request: "GET /monitoring/monitoringboard HTTP/1.1", upstream: "http://127.0.0.1:3003/monitoringboard", host: "10.20.3.249

有人有建议吗?谢谢

我终于找到解决办法了。

nginx.config:

location /monitoring {
    proxy_pass http://localhost:3003;
    ...
}

supervisord.confg:

[program:monitoring]
....
environment=PORT="3003,ROOT_URL="http://10.20.3.249/monitoring", MONGO_URL="mongodb://<username>:<password>@localhost:27017/monitoring"