我正在尝试使用以下虚拟主机运行通过nginx代理的Rails 3应用程序到独角兽。
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;
}
}
}
当我启动独角兽并尝试发出POST请求时,它会在Unicorn日志中显示为GET请求。
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
我是nginx的新手,但似乎不知何故POST请求没有通过。我无法在任何地方找到proxy_cache_methods
set explicity(nginx config,虚拟主机),但我也设置了明确允许在此虚拟主机中使用POST:proxy_cache_methods GET HEAD POST;
虚拟主机是否包含此行没有任何区别。
我认为不值得发布unicorn.rb配置文件,因为它似乎是nginx代理的问题,但如果需要我可以做。
答案 0 :(得分:2)
在location
块下,似乎还需要以下内容:
proxy_set_header X-FORWARDED_PROTO https;