简体   繁体   English

使用 Nginx 反向代理的节点 JS 托管给出 404 错误

[英]Node JS hosting using Nginx Reverse proxy gives 404 error

I want to host a Nodejs API server to my digitalocean server where a WordPress application is already running using Nginx and PHP fpm我想将 Nodejs API 服务器托管到我的 digitalocean 服务器,其中 WordPress 应用程序已经使用 Nginx 和 PHP fpm 运行

I followed the below link to set up the WordPress application and it's working fine now.我按照以下链接设置了 WordPress 应用程序,现在运行良好。 https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-web-server-and-reverse-proxy-for-apache-on-one-ubuntu-18-04-server https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-web-server-and-reverse-proxy-for-apache-on-one-ubuntu-18-04-服务器

I wanted to set up Nodejs application inside the same server for demo purposes and I followed the digitalocean guide for setting up node.js with a different config file and subdomain.为了演示目的,我想在同一台服务器内设置 Nodejs 应用程序,我按照 digitalocean 指南使用不同的配置文件和子域设置 node.js。

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node.js-application-for-production-on-ubuntu-16-04 https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node.js-application-for-production-on-ubuntu-16-04

My Nginx config for node application looks like this我的 Nginx 节点应用程序配置如下所示

server {
server_name sub.domain.com
location / {
    proxy_pass http://localhost:6969;
    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;
}

} }

I have allowed port 6969 using ufw allow 6969 .我已经使用ufw allow 6969 允许端口 6969

I am able to access the Nodejs application using sub.domain.com:6969 but sub.domain.com gives me a 404 error.我可以使用sub.domain.com:6969访问 Nodejs 应用程序,但是sub.domain.com给我一个 404 错误。 (404 Not Found nginx/1.18.0 (Ubuntu)) (404 未找到 nginx/1.18.0 (Ubuntu))

I want to access Nodejs application directly without a port number.我想在没有端口号的情况下直接访问 Nodejs 应用程序。 I have checked Nginx logs and there are no errors, and configures is gives success in nginx -t我已经检查了 Nginx 日志并且没有错误,配置在nginx -t中成功

Please give me some suggestions to debug and fix this issue.请给我一些调试和解决此问题的建议。 I don't have much knowledge in Nginx configuration.我对 Nginx 配置了解不多。 I was just following tutorials from Digitalocean to configure the WordPress and node application.我只是按照 Digitalocean 的教程来配置 WordPress 和节点应用程序。

Thanks in Advance提前致谢

You are missing the port你错过了港口

server {
server_name sub.domain.com;
listen: 80;

location / {
    proxy_pass http://localhost:6969;
    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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM