Nginx Reverse Proxy for Mochiweb Custom Application

I have Nginx since my external server server is listening on port 80. And with some requests, I configured nginx to cancel the proxy server on the mochiweb web server that I wrote while listening on port 8000. My nginx configuration for this looks like this way:

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 go to the URL http: // localhost / mymochiserver , I do not see the answer in the browser. The browser just says "Waiting for localhost." mymochiserver prints some trace in the terminal window from which it starts, whenever a user connects to it, and right now I see a trace for every browser window that I open to connect this URL. But I do not see any output that I expect to see in the browser. BUT, when I get direct access to the URL http://127.0.0.1:8000/ , everything works fine, and I see the output of mymochiserver in the browser. This way it works with a direct call. But when the reverse proxy through nginx, it seems to not work. Any idea what could be wrong?


Update: In my Mochiweb application, I have the following lines of code:

 Socket = Req:get(socket), inet:setopts(Socket, [{active, once}]), proc_lib:hibernate(?MODULE, feed, [Response, Userid, 1]); 

This is basically a COMET application where users will connect to mymochiserver, and the server pushes data to all connected clients. If there is no data to send from the server, I am a sleeping process. And then, when I woke up, I call the feed function to send data. And if I delete the sleeping code, everything will be fine, and I will see the output in the browser. But if I winter, it will not work. Any idea what goes wrong?

+4
source share
1 answer

Fixed!

Link: http://timanovsky.wordpress.com/2009/01/09/toward-a-million-user-long-poll-http-application-nginx-erlang-mochiweb/

I had to disable proxy buffering and increase proxy_read_timeout in nginx to make it work. So my configuration file is as follows:

 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; } 

Thanks thomas55 for indicating the answer!

+4
source

Source: https://habr.com/ru/post/1286339/


All Articles