【问题标题】:How to remove port number from url, and add slug with node app?如何从 url 中删除端口号,并使用节点应用程序添加 slug?
【发布时间】:2019-01-16 18:09:00
【问题描述】:

我已经在 nginx 上部署了 nodebb 应用程序,并尝试与我的站点结合。

我的网站是http://example.com。 我成功地在http://example.com:4567 上显示节点应用程序或者http://example.com(port 号码被删除)。

但是,我想用http://example.com/nodebb 之类的网址向他们展示。

我尝试了下面的代码。

config.json

{
    "url": "http://example.com/nodebb",
    "secret": "secret",
    "database": "mongo",
    "port": 4567,
    "mongo": {
        "host": "127.0.0.1",
        "port": "27017",
        "username": "nodebb",
        "password": "pass",
        "database": "nodebb"
    }
}

nginx.conf

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://127.0.0.1/nodebb:4567;
    proxy_redirect off;
    # Socket.IO Support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

但是,它返回“未找到”。 我不知道如何制作新的 slug 并将节点应用程序放入其中。 任何帮助表示赞赏。

【问题讨论】:

标签: node.js nginx google-cloud-platform bitnami nodebb


【解决方案1】:

您对问题有正确的答案,您只需要在您的 proxy_pass 中添加更多选项即可完全解决您的问题。

我认为这篇文章回答了你的问题:https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 2011-02-04
    • 2020-03-02
    • 2014-12-18
    • 2014-07-18
    相关资源
    最近更新 更多