将 NGINX 请求传递给 Express 的配置



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

下面来自DigitalOcean的示例首先适用于https网站吗?我不应该配置NGINX用于表达的相同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开头的任何 API 请求,例如:http://localhost:3000/update、http://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;
}

最新更新