node.js - 如何修复仅在节点应用程序上加载主页,其他路由给出 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;
}
}
解决方案
推荐阅读
- python - 如何使用 pip 安装 requests 模块?
- microsoft-graph-api - microsoft graph API 中的 preferredDataLocation 字段在 v1.0 中不起作用
- java - 你将如何在java8中将方法转换为单行
- ios - 如何将 Picker 转换为 TextField?
- wordpress - 如何在强大的 Wordpress 插件中更改下拉列表的提交值的大小写?
- node.js - Node.js MongoDB 在 Client.close() 上崩溃
- keras - keras 中的早期停止回调
- vue.js - 如何将多个 vue 组件变成一个 npm 包?
- mongodb - 展开嵌套对象数组后的Mongodb总和
- apache-spark - 多个 spark 作业写入同一个 hive 分区外部表 - spark 2.3