我有Nginx作为我的前端Web服务器在端口80上侦听。并且某些请求,我已经设置了nginx来反向代理它到我写的基于mochiweb的web服务器,在端口8000上监听。我的nginx配置为这看起来像这样:
location /mymochiserver { proxy_pass http://127.0.0.1:8000; 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; 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; }现在,当我访问URL http:// localhost / mymochiserver时,我在浏览器上看不到响应。 浏览器只是说“等待localhost”。 mymochiserver将一些跟踪打印到运行它的终端窗口,每当用户连接到它时,现在,我确实看到我打开的每个浏览器窗口的跟踪以连接此URL。 但我没有看到任何我希望看到写入浏览器的输出。 但是,当我直接访问URL http://127.0.0.1:8000/时,一切正常,我在浏览器上看到mymochiserver的输出。 所以它直接调用时有效。 但是当通过nginx反向代理时,它似乎不起作用。 知道什么可能是错的吗?
更新:在我的Mochiweb应用程序中,我有以下代码行:
Socket = Req:get(socket), inet:setopts(Socket, [{active, once}]), proc_lib:hibernate(?MODULE, feed, [Response, Userid, 1]);它基本上是一个COMET应用程序,用户将连接到mymochiserver,服务器将数据推送到所有连接的客户端。 如果没有数据要从服务器发送,我会暂停该过程。 然后当我醒来时,我调用feed函数发送数据。 如果我删除休眠代码,一切正常,我在浏览器中看到输出。 但如果我做休眠,它就行不通。 知道出了什么问题吗?
I have Nginx as my front-end web server listening on port 80. And certain requests, I've set up nginx to reverse proxy it to a mochiweb based web server that I've written, listening on Port 8000. My nginx configuration for this looks like this:
location /mymochiserver { proxy_pass http://127.0.0.1:8000; 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; 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; }Now, when I access the URL http://localhost/mymochiserver I don't see a response on the browser. The browser just says "Waiting for localhost". mymochiserver prints some trace to the terminal window from which it is run, whenever a user connects to it, and right now, I do see the trace for each browser window I open to connect this URL. But I don't see any of the output I'm expecting to see being written to the browser. BUT, when I directly access the URL http://127.0.0.1:8000/ everything works fine, and I see the output from mymochiserver on the browser. So it works when directly called. But when reverse-proxied through nginx, it doesn't seem to be working. Any idea what could be wrong?
Update: In my Mochiweb application I have these lines of code:
Socket = Req:get(socket), inet:setopts(Socket, [{active, once}]), proc_lib:hibernate(?MODULE, feed, [Response, Userid, 1]);It is basically a COMET application where users will connect to the mymochiserver and the server pushes out data to all the connected clients. If there is no data to be sent from the server, I hibernate the process. And then when woken up, I call the feed function to send out the data. And if I remove the hibernation code, everything works well, and I see output in the browser. But if I do hibernate, it doesn't work. Any idea what's going wrong?
最满意答案
固定!
参考: http : //timanovsky.wordpress.com/2009/01/09/toward-a-million-user-long-poll-http-application-nginx-erlang-mochiweb/
我不得不关闭代理缓冲并增加nginx中的proxy_read_timeout以使其工作。 所以我的配置文件现在看起来像这样:
location /mymochiapp { proxy_pass http://127.0.0.1:8000; 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; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 3600; proxy_buffering off; }谢谢thomas55指出答案!
Fixed!
Reference: http://timanovsky.wordpress.com/2009/01/09/toward-a-million-user-long-poll-http-application-nginx-erlang-mochiweb/
I had to turn off proxy buffering and increase the proxy_read_timeout in nginx to make it work. So my config file looks like this now:
location /mymochiapp { proxy_pass http://127.0.0.1:8000; 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; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 3600; proxy_buffering off; }Thank you thomas55 for pointing out the answer!
更多推荐
发布评论