<p><br>
On Oct 2, 2012 9:44 PM, "jwxie" <<a href="mailto:nginx-forum@nginx.us">nginx-forum@nginx.us</a>> wrote:<br>
><br>
> My proxy server runs on ip A and this is how people access my web service.<br>
> The nginx configuration will redirect to a virtual machine on ip B.<br>
><br>
> For the proxy server on IP A, I have this in my sites-available<br>
><br>
> server {<br>
>         listen 443;<br>
>         ssl on;<br>
>         ssl_certificate nginx.pem;<br>
>         ssl_certificate_key nginx.key;<br>
><br>
>         client_max_body_size 200M;<br>
>         server_name localhost 127.0.0.1;<br>
>         server_name_in_redirect off;<br>
><br>
>         location / {<br>
>                 proxy_pass <a href="http://10.10.0.59:80">http://10.10.0.59:80</a>;<br>
>                 proxy_redirect <a href="http://10.10.0.59:80/">http://10.10.0.59:80/</a> /;<br>
><br>
>                 proxy_set_header Host $http_host;<br>
>                 proxy_set_header X-Real-IP $remote_addr;<br>
>                 proxy_set_header X-Forwarded-For<br>
> $proxy_add_x_forwarded_for;<br>
>         }<br>
><br>
> }<br>
><br>
> server {<br>
>         listen 80;<br>
>         rewrite     ^(.*)   https://$http_host$1 permanent;<br>
>         server_name localhost 127.0.0.1;<br>
>         server_name_in_redirect off;<br>
>         location / {<br>
>                 proxy_pass <a href="http://10.10.0.59:80">http://10.10.0.59:80</a>;<br>
>                 proxy_redirect <a href="http://10.10.0.59:80/">http://10.10.0.59:80/</a> /;<br>
>                 proxy_set_header Host $http_host;<br>
>                 proxy_set_header X-Real-IP $remote_addr;<br>
>                 proxy_set_header X-Forwarded-For<br>
> $proxy_add_x_forwarded_for;<br>
>         }<br>
> }<br>
><br>
> The proxy_redirect was taken from how do I get nginx to forward HTTP POST<br>
> requests via rewrite?<br>
><br>
> Everything that hits the public IP will hit 443 because of the rewrite.<br>
> Internally, we are forwarding to 80 on the virtual machine.<br>
><br>
> But when I run a python script such as the one below to test our<br>
> configuration<br>
><br>
> import requests<br>
><br>
> data = {'username': '....', 'password': '.....'}<br>
> url = '<a href="http://IP_A/api/service/signup">http://IP_A/api/service/signup</a>'<br>
><br>
> res  = requests.post(url, data=data, verify=False)<br>
> print res<br>
> print res.json<br>
> print res.status_code<br>
> print res.headers<br>
><br>
> I am getting a 405 Method Not Allowed. In nginx we found that when it hit<br>
> the internal server, the internal nginx was getting a GET request, even<br>
> though in the original header we did a POST (this was shown in the Python<br>
> script).<br>
><br>
> So it seems like rewrite has problem. </p>
<p>Rewrite has no problem. It doesn't dictate a verb that the client should use. The user-agent you're using is choosing to do this, possibly correctly, upon receipt of the 301 response.</p>
<p>Have a read of the 301, 302, 303, 307 and 308 sections here for more information: <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection">http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection</a></p>

<p>Your options appear to be to use an experimental response code, or to enforce that clients POST to the correct port. I'd choose the latter if at all possible.</p>
<p>Jonathan</p>