nginx 仅向 unicorn 发送 GET 请求
我正在尝试使用以下虚拟主机运行通过 nginx 代理到 unicorn 的 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;
}
}
}
当我启动 unicorn 并尝试发出 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 请求没有被发送。我找不到在任何地方(nginx 配置、虚拟主机)显式设置 proxy_cache_methods,但我也显式设置它以允许在此虚拟主机中进行 POST:proxy_cache_methods GET HEAD POST; 虚拟主机是否包含此行没有任何区别。
我认为不值得发布 unicorn.rb 配置文件,因为它似乎是 nginx 代理的问题,但如果需要我可以这样做。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来这还需要
location
块下的以下内容:It seems this also needs the following under the
location
block: