Nginx反向代理到apache-wordpress可以工作,但是proxy_pass到外部URL失败 [英] nginx reverse proxy to apache-wordpress works but proxy_pass to external url fails

查看:238
本文介绍了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://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 config中的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天全站免登陆