【问题标题】:Nginx with wordpress, use reverse proxy as fallbackNginx 与 wordpress,使用反向代理作为后备
【发布时间】:2019-05-21 04:05:36
【问题描述】:

我正在尝试设置 nginx 以按以下顺序尝试文件:

1) 查看文件是否直接存在于服务器上 2)查看文件是否作为wordpress的一部分存在 3) 如果 1 或 2 都不存在,则回退到外部服务器。

我有以下设置:

location / {
    try_files $uri $uri/ /index.php?q=$uri&$args @proxy;
}

location @proxy {
    proxy_pass      https://external.website.com;
}

这对 wordpress 不起作用,而且 nginx 的 try_files 文档非常无用。我可以看到最后一个 arg 是后备,所以我尝试翻转最后两个 args,这导致 wordpress 工作,但反向代理不起作用。

【问题讨论】:

    标签: wordpress nginx reverse-proxy


    【解决方案1】:

    我想我解决了。从技术上讲,这首先检查代理,但这对于我想要做的事情没关系。如果有人解决了正确的方法,我会选择他们。

        location / {
            try_files $uri $uri/ @proxy;
        }
    
        location @proxy {
            proxy_pass      https://external.website.com;
            proxy_intercept_errors on;
            recursive_error_pages on;
            error_page 404 = @wordpress;
        }
    
        location @wordpress{
            try_files $uri /index.php?q=$uri&$args;
        }
    
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    

    【讨论】:

      猜你喜欢
      • 2019-08-31
      • 2015-10-06
      • 2017-09-06
      • 2020-06-23
      • 2018-05-10
      • 2021-08-18
      • 1970-01-01
      • 2021-06-17
      相关资源
      最近更新 更多