nginx 뒤에서 2개의 앱 실행

nginx 뒤에서 2개의 앱 실행

나는 아직 nginx를 모른다. DevOps 담당자가 우리 앱을 위해 잠시 전에 하나를 설정했습니다.

이것이 nginx.conf그가 설정한 것입니다.

user www-data; 
worker_processes auto; 
pid /run/nginx.pid; 

events { 
worker_connections 768; 
multi_accept on; 
} 

http { 
sendfile on; 
tcp_nopush on; 
tcp_nodelay on; 
keepalive_timeout 65; 
types_hash_max_size 2048; 
include /etc/nginx/mime.types; 
default_type application/octet-stream; 
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE 
ssl_prefer_server_ciphers on; 
access_log /var/log/nginx/access.log; 
error_log /var/log/nginx/error.log; 
gzip on; 
gzip_disable "msie6"; 


proxy_cache_path /home/html_catch levels=1:2 keys_zone=appbacktocartcocatch:2m max_size=50m; 
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args"; 
proxy_cache_valid 200 302 10m; 
proxy_cache_valid 404 1m; 




include /etc/nginx/sites-enabled/*.conf; 




}

include특별히 앱용인 이와 유사한 다른 파일이 있다는 것을 알 수 있습니다.

#proxy_cache_path /home/html_catch levels=1:2 keys_zone=appbacktocartcocatch:2m max_size=50m; 
#proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args"; 
#proxy_cache_valid 200 302 10m; 
#proxy_cache_valid 404 1m; 


upstream appbacktocartco { 
# server localhost:3000; 
server localhost:3001; 
} 


server { 
listen 145.239.24.196:80; 
server_name app.backtocart.co; 

location / { 

proxy_cache appbacktocartcocatch; 

proxy_set_header Host $host; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_set_header X-Forwarded-Proto $scheme; 
proxy_http_version 1.1; 
proxy_set_header Upgrade $http_upgrade; 
proxy_set_header Connection "upgrade"; 
proxy_pass http://appbacktocartco; 
proxy_read_timeout 90; 
} 


listen 443 ssl; # managed by Certbot 
ssl_certificate /etc/letsencrypt/live/app.backtocart.co/fullchain.pem; # managed by Certbot 
ssl_certificate_key /etc/letsencrypt/live/app.backtocart.co/privkey.pem; # managed by Certbot 
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot 
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot 


if ($scheme != "https") { 
return 301 https://$host$request_uri; 
} # managed by Certbot 

}

이제 포트 5000에서 이와 같은 다른 앱을 실행하면 됩니다. 이 파일을 복사하여 몇 가지 사항을 변경한 다음 nginx를 다시 시작했지만 이해할 수 없는 오류가 발생했습니다. 이것 좀 도와주실 수 있나요?

편집하다

내가 시도한 방법은 다음과 같습니다.

# proxy_cache_path /home/html_catch levels=1:2 keys_zone=appbacktocartcocatch:2m max_size=50m; 
# proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args"; 
# proxy_cache_valid 200 302 10m; 
# proxy_cache_valid 404 1m; 


upstream appbacktocartco { 
  # server localhost:3000; 
  server localhost:5000; 
} 


server { 
listen 145.239.24.196:80; 
server_name chatservice.backtocart.co; 

  location / { 

    proxy_cache chatservicebacktocartcocatch; 

    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_pass http://chatservicebacktocartco; 
    proxy_read_timeout 90; 
  } 
}

그럼 내가 할게

/etc/init.d/nginx restart

그리고 얻다

[....] Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
 failed!

systemctl status nginx.service이것을 가져온다

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2018-02-20 13:24:26 CET; 3min 4s ago
  Process: 28185 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=2)
  Process: 17317 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 28188 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 17319 (code=exited, status=0/SUCCESS)

Feb 20 13:24:26 ns3068281 systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 20 13:24:26 ns3068281 nginx[28188]: nginx: [emerg] duplicate upstream "appbacktocartco" in /etc/nginx/sites-enabled/chatservice.backtocart.co.conf:7
Feb 20 13:24:26 ns3068281 nginx[28188]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 20 13:24:26 ns3068281 systemd[1]: nginx.service: Control process exited, code=exited status=1
Feb 20 13:24:26 ns3068281 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Feb 20 13:24:26 ns3068281 systemd[1]: nginx.service: Unit entered failed state.
Feb 20 13:24:26 ns3068281 systemd[1]: nginx.service: Failed with result 'exit-code'.

그리고 journalctl -xe이걸 가져온다

Feb 20 13:25:12 ns3068281 sshd[28260]: input_userauth_request: invalid user ts3 [preauth]
Feb 20 13:25:12 ns3068281 sshd[28260]: pam_unix(sshd:auth): check pass; user unknown
Feb 20 13:25:12 ns3068281 sshd[28260]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=158.69.204.69
Feb 20 13:25:14 ns3068281 sshd[28260]: Failed password for invalid user ts3 from 158.69.204.69 port 45584 ssh2
Feb 20 13:25:14 ns3068281 sshd[28260]: Received disconnect from 158.69.204.69 port 45584:11: Normal Shutdown, Thank you for playing [preauth]
Feb 20 13:25:14 ns3068281 sshd[28260]: Disconnected from 158.69.204.69 port 45584 [preauth]
Feb 20 13:26:00 ns3068281 nrpe[28264]: ERROR: my_system() seteuid(0): Operation not permitted
Feb 20 13:26:01 ns3068281 CRON[28267]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 20 13:26:01 ns3068281 CRON[28268]: (root) CMD (/usr/local/rtm/bin/rtm 41 > /dev/null 2> /dev/null)
Feb 20 13:26:01 ns3068281 CRON[28267]: pam_unix(cron:session): session closed for user root
Feb 20 13:27:01 ns3068281 CRON[28310]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 20 13:27:01 ns3068281 CRON[28311]: (root) CMD (/usr/local/rtm/bin/rtm 41 > /dev/null 2> /dev/null)
Feb 20 13:27:01 ns3068281 CRON[28310]: pam_unix(cron:session): session closed for user root
Feb 20 13:27:17 ns3068281 nrpe[28355]: ERROR: my_system() seteuid(0): Operation not permitted
Feb 20 13:27:47 ns3068281 sshd[28415]: Invalid user ts3 from 158.69.204.69
Feb 20 13:27:47 ns3068281 sshd[28415]: input_userauth_request: invalid user ts3 [preauth]
Feb 20 13:27:47 ns3068281 sshd[28415]: pam_unix(sshd:auth): check pass; user unknown
Feb 20 13:27:47 ns3068281 sshd[28415]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=158.69.204.69
Feb 20 13:27:49 ns3068281 sshd[28415]: Failed password for invalid user ts3 from 158.69.204.69 port 38540 ssh2
Feb 20 13:27:49 ns3068281 sshd[28415]: Received disconnect from 158.69.204.69 port 38540:11: Normal Shutdown, Thank you for playing [preauth]
Feb 20 13:27:49 ns3068281 sshd[28415]: Disconnected from 158.69.204.69 port 38540 [preauth]
Feb 20 13:28:01 ns3068281 CRON[28417]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 20 13:28:01 ns3068281 CRON[28418]: (root) CMD (/usr/local/rtm/bin/rtm 41 > /dev/null 2> /dev/null)
Feb 20 13:28:01 ns3068281 CRON[28417]: pam_unix(cron:session): session closed for user root
lines 1012-1035/1035 (END)

답변1

업스트림을 구성하는 구성 파일에 오류가 있습니다.

upstream appbacktocartco { 
    # server localhost:3000; 
    server localhost:5000; 
}

이 작업을 수행하려면 업스트림에 대해 다른 이름을 사용해야 합니다.

또한 두 번째 구성 파일에서 사용하는

proxy_pass http://chatservicebacktocartco;

해당 업스트림과 일치해야 합니다.

또한 오류 메시지( nginx: [emerg] duplicate upstream "appbacktocartco")에서는 이를 문제로 지정합니다.

관련 정보