【发布时间】:2018-09-14 17:11:57
【问题描述】:
我有一个使用这种结构运行的 Ubuntu Web 服务器:
Nginx 反向代理 localhost:80,它重定向到 '/'(在 localhost:8080 具有 WordPress 站点的 apache 服务器),目前可以工作。
最近我尝试在www.site.com/app 或内部localhost:3000 添加一个Node.js 应用程序。我能够提供 node.js webapp 的 HTML 和 CSS,但是所有内部路由调用都在 404ing,可能是因为 /app/ 的 URL 寻址。
IE。尝试访问 /someendpoint 和 404,因为 Node.js 在技术上运行在 localhost:3000 (www.site.com/app) 上。我应该像 (www.site.com/app/someendpoint) 这样路由参数吗?
问题:由于我对 NGINX 配置的理解不好,来自 NODE.JS 的所有 POST/GET 调用都是 404ing。如何将此 GET 调用路由到 Node.js 服务器的实际位置,即 (site.com/app/, localhost:3000)。
这是我来自 /etc/nginx/available_sites/. 的“default”配置
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name www.*site*.name;
location / {
proxy_pass http://127.0.0.1:8080$request_uri;
proxy_buffering on;
proxy_buffers 12 12k;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
#Currenly serving HTML, CSS of site, however node routes 404
location /app/ {
proxy_pass http://localhost:3000/;
}
}
我如何更新这个 NGINX 配置文件来说明节点端点主动尝试访问我的 apache 站点的路由,而不是节点服务器的 /app 实际位置?
任何帮助或想法都会很棒,作为个人项目的一部分,我已经在这个问题上停留了一段时间。
谢谢!
【问题讨论】: