来自多个上游服务器的Nginx反向代理

时间:2019-11-22 01:16:18

标签: wordpress nginx reverse-proxy nginx-reverse-proxy netlify

我正在与gatsby一起使用wordpress并托管该站点以进行netlify。最近netlify宕机了,这使我的网站宕机了几个小时。我决定设置一个备份代理。

我试图在上游设置两个源,它们位于自己的nginx服务器上,您可以在配置的底部看到它们

我之所以这样做,是因为当我在master.a2df1.amplifyapp.com;块中添加原始URL mysite.netlify.comupstream { }时,我不断遇到关于Cloudfront设置的upstream prematurely closed connection while reading response header from upstream或Amazon错误等等

如果我将此块更改为一个来源,则一切正常。因此,我不确定为什么不能只在upstream block中声明两个源。

location / { proxy_intercept_errors on; proxy_pass mysite.netlify.com; }

upstream static.com {
  server netlify.com;
  server aws.com backup;
}


server {

    listen 443 ssl;
    server_name  www.test.com;

    root /var/www/html;
    index index.php index.html index.htm;

    access_log  /var/log/nginx/mc-access.log;
    error_log  /var/log/nginx/mc-error.log;

    client_max_body_size 100M;

    ssl_certificate /etc/letsencrypt/live/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
      proxy_intercept_errors on;
      proxy_pass http://static.com;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/www.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param   PATH_INFO       $fastcgi_path_info;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
    }
}


server {

    listen 80;
    server_name netlify.com;

    access_log  /var/log/nginx/mc-access.log;
    error_log  /var/log/nginx/mc-error.log;

    location / {
        proxy_pass https://mysite.netlify.com;
    }
}

server {

    listen 80;
    server_name aws.com;

    access_log  /var/log/nginx/mc-access.log;
    error_log  /var/log/nginx/mc-error.log;

    location / {
        proxy_pass https://master.a2df1.amplifyapp.com;
    }
}

0 个答案:

没有答案
相关问题