nginx 反向代理到 apache-wordpress 有效,但 proxy_pass 到外部 url 失败 [英] nginx reverse proxy to apache-wordpress works but proxy_pass to external url fails

查看:45
本文介绍了nginx 反向代理到 apache-wordpress 有效,但 proxy_pass 到外部 url 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于 apache wordpress 的 nginx 反向代理设置,它工作正常.但是,根据位置需要重定向到失败的外部 url.请检查以下配置.这是有效的设置吗?

I have a nginx reverse proxy setup for apache wordpress which works fine. However based on location need to redirect to an external url which fails. Please check the below config. Is this a valid setup ?

https://platform.com/ - 这有效 - 任何后续的 wp 页面也有效

https://platform.com/ - this works - also any subsequent wp pages also works

https://platform.com/pen - 这需要重定向到 https://abcdef.com - 这不起作用 - 404 页面加载错误 有帮助吗?

https://platform.com/pen - this needs to redirect to https://abcdef.com - this doesn't work - 404 page load error Any help ?

server {
    listen 443 ssl default_server;
    listen [::]:443 default_server;

    server_name platform.com;
    server_tokens off;

    root /var/www/html/def/public/;
    index index.php;

    ssl on;
    ssl_certificate /tmp/fgh.crt;
    ssl_certificate_key /tmp/fgh.pem;

    access_log /var/log/nginx/access2.log;
    error_log /var/log/nginx/error2.log;

    location / {
            proxy_set_header X-Forwarded-Proto $scheme;
            try_files $uri @apache;
    }

    location @apache {
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8080;
    }

     location ~[^?]*/$ {
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8080;
     }

     location /pen {
            proxy_pass https://abcdef.com;
    }
   }

推荐答案

将服务器名称(wordpress 站点)从 http 前缀更改为 www 前缀后,代理传递重新指示有效.不得不将所有 http https 服务器块重定向到 nginx 配置中的 www 服务器块

After changing the server name (wordpress site) from http prefix to www prefix, proxy pass re directions worked. Had to redirect all http https server blocks to www server block in nginx config

这篇关于nginx 反向代理到 apache-wordpress 有效,但 proxy_pass 到外部 url 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆