在Nginx中重写不适用于POST请求

我有两个VPS(一个用于故障转移),都运行Nginx作为后端服务器的负载平衡器。 另外,我已经在Nginx上为我的域(在GoDaddy.com上注册)启用并configuration了SSL。

由于我正在使用DNS Alogging来configurationVPS故障转移的域,因此我无法input端口号(只允许IP号码)。因此,默认情况下域名ping端口80.但ssl侦听端口443。

为此,我在nginx的服务器块中使用rewrite方法,但不适用于POST请求。 虽然它适用于GET请求。 我知道proxy_pass可以与POST请求一起使用,但这不是正确的做法(不安全)。 我应该直接在HTTPS连接上发布请求。

这里是我的nginx conf:

upstream tomcat_servers{ least_conn; server 123.45.678.90:8080; server 124.345.78.23:8180; } server { listen 80; server_name thedomain.com; rewrite ^(.*) https://$host$request_uri? permanent; } server { listen 443; server_name thedomain.com; ....ssl config..... location / { proxy_pass http://tomcat_servers; proxy_http_version 1.1; proxy_connect_timeout 30s; proxy_read_timeout 30s; proxy_send_timeout 30s; proxy_next_upstream timeout; proxy_next_upstream error invalid_header http_500 http_502 http_404 http_503 http_504; } } 

我应该如何configuration使其在给定的情况下与POST请求一起工作。

谢谢

你不应该使用redirect的职位。 如果你必须,你应该使用307代码发布。 最终用户可能会被提示redirect。

W3C规范 – RFC 2616

301永久移动如果接收到301状态码以响应除GET或HEAD之外的请求,用户代理不能自动redirect请求,除非用户可以确认,因为这可能会改变请求的条件发行。

注意:在 收到301状态码 后自动redirectPOST请求时 ,一些现有的HTTP / 1.0用户代理 将错误地将其更改为GET请求。

307临时redirect如果接收到307状态码以响应除GET或HEAD之外的请求,则用户代理绝不能自动redirect请求,除非用户可以确认,因为这可能会改变请求的条件发行。

看看这里

您应该修复您的应用程序,使其仅使用https://domain.com/page//domain.com/page格式的url。

redirect规则应该只是为了方便用户使用,只要input域名即可首次访问该站点。

谢谢@filmonic和Tero纠正我,每个人都build议redirect不是POST请求的最佳做法,所以我做了我的服务器端networking的体系结构的变化。 它工作。 我的架构现在看起来有点像这样

  ________________ | | | CLIENT | | WEB BROWSER | |________________| || || SSL _______\/_______ | | | DNS SERVER | | (NEW YORK) | |________________| || || _______/ \_______ / \ / SSL \ SSL ____________________ ____________________ | | | | | SAN FRANCISCO | | NEW YORK | |____________________| |____________________| | ______________ | | ______________ | | | | | | | | | | | APP | | | | APP | | | | LOAD BALANCE | | | | LOAD BALANCE | | | | PROXY | | | | PROXY | | | |_____ _____| | | |_____ _____| | |________| |________| |________| |________| || __ __ || ||<=====||==================||=====>|| \/ \/ \/ \/ ____________________ ____________________ | | | | | SAN FRANCISCO | | NEW YORK | |____________________| |____________________| | ______________ | | ______________ | | | | | | | | | | | APP SERVERS | | | | APP SERVERS | | | |______ ______| | | |______ ______| | | ______||______ | | ______||______ | | | | | | | | | | | DATABASE |<==================>| DATABASE | | | |______________| | MASTER-SLAVE | |______________| | |____________________| |____________________|