James I
James I

Reputation: 198

nginx only sending GET requests to unicorn

I'm trying to run a Rails 3 app proxied through nginx to unicorn, using the following virtual host.

upstream nginx {
  server unix:/tmp/nginx.socket fail_timeout=0;
}

server {
    listen 80;
    server_name nginx.domain.net;

    rewrite ^(.*) https://nginx.mydomain.net$1 permanent;
}


server {
    listen 443 ssl;
    server_name nginx.mydomain.net;

    root /home/me/nginx.mydomain.net/current/public;
    access_log /home/me/nginx.mydomain.net/shared/log/access.log;
    error_log /home/me/nginx.mydomain.net/shared/log/error.log;

    ssl_certificate /etc/nginx/certs/my_crt_chain.crt;
    ssl_certificate_key /etc/nginx/certs/my_crt_key.key;

    rewrite_log on;

    location / {
        proxy_redirect     off;

        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_cache_methods GET HEAD POST;

        client_max_body_size       10m;
        client_body_buffer_size    128k;

        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;

        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;

        if (!-f $request_filename) {
          proxy_pass http://nginx;
          break;
        }

    }
}

When I start unicorn and attempt to make a POST request, it's showing up in the Unicorn logs as a GET request.

I, [2011-09-30T12:38:05.036462 #19364]  INFO -- : unlinking existing socket=/tmp/nginx.socket
I, [2011-09-30T12:38:05.036902 #19364]  INFO -- : listening on addr=/tmp/nginx.socket fd=5
I, [2011-09-30T12:38:05.037435 #19364]  INFO -- : Refreshing Gem list
master process ready
worker=0 ready
worker=1 ready
92.22.194.68 - - [30/Sep/2011 12:38:13] "GET /reset HTTP/1.0" 200 - 0.6486

I'm new to nginx but it seems that somehow the POST requests aren't being sent through. I can't find proxy_cache_methods set explicity anywhere (nginx config, virtual host) but I've also set it explicity to allow POST in this virtual host: proxy_cache_methods GET HEAD POST; Whether the virtual host includes this line or not doesn't make any difference.

I didn't think it was worth posting the unicorn.rb configuration file as it seems to be an issue with nginx's proxying, but I can do if needed.

Upvotes: 1

Views: 1084

Answers (1)

James I
James I

Reputation: 198

It seems this also needs the following under the location block:

    proxy_set_header X-FORWARDED_PROTO https;

Upvotes: 2

Related Questions