NGINX将网络流量重定向到Netlify网站

NGINX将网络流量重定向到Netlify网站,nginx,networking,reverse-proxy,Nginx,Networking,Reverse Proxy,我有一台Nginx web服务器,可将流量直接重定向到mydomain.com,连接方式为: Wordpress网站 节点API 现在我想将所有流量直接重定向到旧的Wordpress网站,转到一个新的Netlify管理的静态网站,该网站的URL类似于purple-rain.Netlify.com 配置的主要部分是: server { listen 443; server_name example.com; # SSH stuff managed by Certbot

我有一台Nginx web服务器,可将流量直接重定向到mydomain.com,连接方式为:

  • Wordpress网站
  • 节点API
现在我想将所有流量直接重定向到旧的Wordpress网站,转到一个新的Netlify管理的静态网站,该网站的URL类似于purple-rain.Netlify.com

配置的主要部分是:

server {
    listen 443;
    server_name example.com;

    # SSH stuff managed by Certbot skipped

    # What is this for?
    root "/var/www/example/httpdocs";
        index index.html index.htm index.php;
    charset utf-8;

    # Redirect everything that starts with "api" or "img" to the Node API
    # like https://example.com/api/r1/users will match this

    location ~ /(api|img) {
        proxy_pass http://localhost:45001;
        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;
    }

    # Redirect to the same Node API (can I merge the two?)

    location ~ /js/react {
        proxy_pass http://localhost:45001;
        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;
    }

    # This redirects everything that does not match to Wordpress?

    location / {
        root /var/www/example-wp/httpdocs;
        try_files $uri $uri/ /index.php?$args;
    }

    # This redirects everything that ends with ".php" to Wordpress?

    location ~* \.php$ {
        root /var/www/example-wp/httpdocs;
        fastcgi_index   index.php;
        fastcgi_pass    unix:/run/php/php7.2-fpm.sock;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}

我必须如何更改此项以将网站流量重定向到新的Netlify支持的网站

使用我尝试的内容进行编辑:

我试图用
proxy\u pass
指令将单个页面(/work with us)重定向到netlify支持的网站,如下所示:

location /work-with-us {
    proxy_pass https://purple-rain.netlify.com;
    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;
}
在添加此页面之前,我从Wordpress网站正确地接收到自定义404页面,因为旧网站上没有此页面。
添加了这个之后,我得到了一个带有“未找到”的nginx404页面