首页 > 解决方案 > 如何修复仅在节点应用程序上加载主页,其他路由给出 404

问题描述

我正在使用 nginx 的服务器块功能在子域上托管我的节点应用程序。但我只能访问应用程序的主页。例如: subdomain.example.com 有效,但 subdomain.example.com/users 给出 404

我遵循了 Digitalocean 上的文档

server {
    listen 80;
    listen [::]:80;
    root /var/www/staging.xxxxxxx.com/html/xxxxxxx/src;

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

    server_name staging.xxxxxxxx.com www.staging.xxxxxxx.com;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            # try_files $uri $uri/ =404;

            proxy_pass http://localhost:3000;
            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;

    }
}

标签: node.jsnginxubuntu-18.04

解决方案


推荐阅读