Nginx 出乎意料 returns 404 for Nodejs API

Nginx unexpectedly returns 404 for Nodejs API

我正在尝试在 Digital Ocean 上使用 Nginx 设置一个 VueJS 前端和一个 NodeJS api 后端服务器。我一直在设置 Nginx 以使其正常工作时遇到问题。

更详细地说明我正在努力实现的目标:

实际发生了什么:

配置

NodeJS api routes 可用的路由应该是 http://myaddress/api 端口 3333:

router.route("/api/:sid").get(getUrlShorten);
router.route("/ai").post(postUrlShorten);

Nginx 配置:

Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;


        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name lien.to;
        location / {
                root /var/www/html/liento-fe/dist;
        }

        location /api/ {
                proxy_pass http://localhost:3333/;
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
         

防火墙(UFW):

Status: active

To                         Action      From
--                         ------      ----
Nginx HTTP                 ALLOW       Anywhere                  
OpenSSH                    ALLOW       Anywhere                  
Nginx HTTP (v6)            ALLOW       Anywhere (v6)             
OpenSSH (v6)               ALLOW       Anywhere (v6)             

另外一个问题:在DO上定位代理地址应该是本地主机还是DO服务器的实际IP?

接下来我可以尝试什么?有什么我想念的吗?

尝试删除 try_files $uri $uri/ =404;:

location /api/ {
  proxy_pass http://localhost:3333/;
}

这对我有用:https://github.com/gabrielwillemann/fast-help/blob/master/nginx/sites-avaible-examples.md#for-mutiple-proxies