在Digitalocean混乱中使用Express和Mongo db部署Angular 2应用

时间:2019-03-16 16:51:54

标签: angular mongodb express digital-ocean pm2

我一直在努力与一整天一起部署Angular 7应用程序以及node,express和mongo,我感到很困惑。有些关于如何在整个互联网中做到这一点的解释并不充分。请帮忙!

我在DigitalOcean上。我已经设置了Nginx,并且可以在我的IP地址上看到Nginx索引页面。我还设置了一个服务器块,其中有两个位置,一个用于我实际的Angular应用程序,另一个用于我的express api。这是代码:

server {

        root /var/www/devgrub.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name devgrub.com www.devgrub.com;

        location / {
                try_files $uri $uri/ =404;
        }

        location /api {
                proxy_pass http://localhost:8080;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
                #try_files $uri $uri/ =404;
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/devgrub.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/devgrub.com/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


}
server {
    if ($host = www.devgrub.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = devgrub.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        listen [::]:80;

        server_name devgrub.com www.devgrub.com;
    return 404; # managed by Certbot

}

/var/www/devgrub.com/html内部,我已上传了运行ng build --prod后生成的Angular应用程序的代码

/home/devgrub内部,我有我的express / node应用程序。

我可以在devgrub.com上成功进入我的Angular应用程序,但是当我去devgrub.com/api时,给我的是hello world,它是我在遵循以下设置教程时制作的原始节点应用程序DigitalOcean。我重新启动了运行PM2的节点应用,现在访问devgrub.com/api时它显示为502 Bad Gateway

我在Angular应用中更改了所有localhost api调用,希望这样做可以但不会。我已经用use devgrub创建了数据库,但是Angular应用似乎无法连接到它,并且由于我对此还很陌生,所以我知道从哪里开始进行故障排除。请帮忙!

更新 这是Nginx错误日志中的一些错误

2019/03/16 17:55:10 [warn] 14358#14358: server name "devgrub.com/api" has suspicious symbols in /etc/nginx/sites-enabled/devgrub-api:8
2019/03/16 17:55:10 [warn] 14358#14358: server name "www.devgrub.com/api" has suspicious symbols in /etc/nginx/sites-enabled/devgrub-api:8
2019/03/16 17:55:10 [notice] 14358#14358: signal process started
2019/03/16 17:56:14 [crit] 14359#14359: *98 SSL_do_handshake() failed (SSL: error:1417D18C:SSL routines:tls_process_client_hello:version too low) while SSL handshaking, client: 184.105.139.70, server: 0.0.0.0:443
2019/03/16 17:57:11 [warn] 14436#14436: server name "devgrub.com/api" has suspicious symbols in /etc/nginx/sites-enabled/devgrub-api:8
2019/03/16 17:57:11 [warn] 14436#14436: server name "www.devgrub.com/api" has suspicious symbols in /etc/nginx/sites-enabled/devgrub-api:8
2019/03/16 17:57:11 [notice] 14436#14436: signal process started
2019/03/16 17:57:22 [error] 14437#14437: *100 connect() failed (111: Connection refused) while connecting to upstream, client: 71.175.29.181, server: devgrub.com, request: "GET /api HTTP/1.1", upstream: "http://127.0.0.1:3000/api", host: "devgrub.com"
2019/03/16 17:57:51 [warn] 14501#14501: server name "devgrub.com/api" has suspicious symbols in /etc/nginx/sites-enabled/devgrub-api:8
2019/03/16 17:57:51 [warn] 14501#14501: server name "www.devgrub.com/api" has suspicious symbols in /etc/nginx/sites-enabled/devgrub-api:8
2019/03/16 17:57:51 [notice] 14501#14501: signal process started
2019/03/16 17:57:52 [error] 14502#14502: *104 connect() failed (111: Connection refused) while connecting to upstream, client: 71.175.29.181, server: devgrub.com, request: "GET /api HTTP/1.1", upstream: "http://127.0.0.1:3000/api", host: "devgrub.com"
2019/03/16 17:57:53 [error] 14502#14502: *104 connect() failed (111: Connection refused) while connecting to upstream, client: 71.175.29.181, server: devgrub.com, request: "GET /api HTTP/1.1", upstream: "http://127.0.0.1:3000/api", host: "devgrub.com"
2019/03/16 17:57:54 [error] 14502#14502: *104 connect() failed (111: Connection refused) while connecting to upstream, client: 71.175.29.181, server: devgrub.com, request: "GET /api HTTP/1.1", upstream: "http://127.0.0.1:3000/api", host: "devgrub.com"
2019/03/16 18:05:21 [error] 14502#14502: *110 connect() failed (111: Connection refused) while connecting to upstream, client: 71.175.29.181, server: devgrub.com, request: "GET /api HTTP/1.1", upstream: "http://127.0.0.1:3000/api", host: "devgrub.com"

1 个答案:

答案 0 :(得分:0)

您好,您好吗,请您分享您的服务器utf防火墙设置,以防万一如果防火墙中不允许使用IP,您可能会遇到这些问题。