Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx:从反向代理重写url中的端口';d应用程序_Nginx_Url_Https_Url Rewriting_Reverse - Fatal编程技术网

Nginx:从反向代理重写url中的端口';d应用程序

Nginx:从反向代理重写url中的端口';d应用程序,nginx,url,https,url-rewriting,reverse,Nginx,Url,Https,Url Rewriting,Reverse,因此,我设置了一个反向代理来隧道我的应用程序 不幸的是,应用程序认为它是通过http而不是https提供服务的,并给出了端口为80的URL 如何在nginx反向代理中处理此问题?(可能通过重写) 当我进入页面时: https://my.server.com php加载,一切正常 单击某个内容后,我有一个如下URL: https://my.server.com:80/page/stuff/?redirect_to 这会在浏览器中引发错误,因为我的反向代理不在端口80上提供SSL。 我怎

因此,我设置了一个反向代理来隧道我的应用程序

不幸的是,应用程序认为它是通过http而不是https提供服务的,并给出了端口为80的URL

如何在nginx反向代理中处理此问题?(可能通过重写)


当我进入页面时:

https://my.server.com 
php加载,一切正常

单击某个内容后,我有一个如下URL:

https://my.server.com:80/page/stuff/?redirect_to
这会在浏览器中引发错误,因为我的反向代理不在端口80上提供SSL。

我怎样才能把它调走?

我当前网站的nginx ssl vhost:

   ... ssl stuff ...
   add_header X-Frame-Options SAMEORIGIN;
   add_header X-Content-Type-Options nosniff;

   location / {
       proxy_pass http://localhost:22228;
       proxy_buffering off;
       proxy_redirect off;
       proxy_read_timeout 43800;
       proxy_pass_request_headers on;
       proxy_set_header Connection "Keep-Alive";
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $remote_addr;
       proxy_set_header Host $host;
       proxy_set_header X-Forwarded-Port 443;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       proxy_pass_header Content-Type;
       proxy_pass_header Content-Disposition;
       proxy_pass_header Content-Length;
       proxy_set_header X-Forwarded-Proto https;
   }

(是的,我知道我的请求头看起来像圣诞树,用于重写响应体,您可以使用:

许多人说(,)在使用
sub_filter
指令时需要禁用压缩:

    proxy_set_header Accept-Encoding "";
    proxy_redirect //my.server.com:80/ //my.server.com/;
对我来说,在配置中没有这一行就可以正常工作,但它可能是OpenResty的一个特性,我使用它来代替nginx

如果您的应用程序生成HTTP 30x重定向,并明确指示domain:port,则您可以使用以下指令重写
Location
头值:

    proxy_set_header Accept-Encoding "";
    proxy_redirect //my.server.com:80/ //my.server.com/;

欢迎使用stackoverflow。您需要在HTTP 3xx重定向头或响应正文中重写这些URL吗?您好,谢谢Ivan。我需要剥离端口并在nginx返回给浏览器的响应中重写URL。与其在nginx上重写响应,不如将应用程序更改为转到HTTP端口80或https端口443,这样就没有问题了没有冲突?我的意思是,https和端口80相处不好。应用程序同时响应https和端口80是很奇怪的。嗨@flaixman。谢谢你的输入。我已经尝试过了,但不幸的是我无法更改应用程序的行为。这个问题是关于通过nginx重写找到解决方案。