【问题标题】:Configuration for passing NGINX request to Express?将 NGINX 请求传递给 Express 的配置?
【发布时间】:2018-04-21 14:00:44
【问题描述】:

我正在创建一个使用 NGINX 处理静态内容、SSL 和所有这些内容的网站,而我的 API 和非静态网站由 Express 处理。 现在,我希望 NGINX 将“/update”之类的东西传递给 Express。但是,我不确定如何配置它。

from DigitalOcean 下面的示例首先是否适用于 https 网站?我不应该配置NGINX用于Express的相同SSL证书,所以它重定向到https://website.com/update而不是http://website.com/update

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

提前致谢!

【问题讨论】:

  • 确切的问题是什么。您想将包含 /update` 的请求传递给 express 服务器还是要将 https://website.com/update 重定向到此 website.com/update `
  • 抱歉,我有点不清楚本质上,我只是想传递给快递服务器@AjitSoman

标签: express nginx


【解决方案1】:

代理传递任何以/update 开头的 API 请求,例如:http://localhost:3000/updatehttp://localhost:3000/update/test 等。您可以在服务器块内使用以下 nginx 配置:

location /update {
        proxy_pass http://localhost:3000;
    }

如果您想将 http://website.com/update 重定向到 https://website.com/update 。您需要在 80 端口创建一个服务器,它将重定向来自 80 端口的任何请求将重定向到 https://website.com/update

server {
    listen 80;
    listen [::]:80;
    server_name website.com;
    return 301 https://website.com$request_uri;
}

【讨论】:

    猜你喜欢
    • 2020-06-16
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 2022-11-28
    相关资源
    最近更新 更多