Aug
20
2013
Nginx proxy for Railo with web sockets
Posted by AJ Mercer at 9:56 am Nginx | Railo | Web Sockets
I have been tinkering with the idea of adding web sockets to a new build of a web site at work so I can push data to the browser. The first obstacle I had to get around was the corporate firewall and navigate through the DMZ. I thought I was going to have to get the network administrator to poke holes in the firewall and add more rules. But then I discovered Nginx can proxy web sockets on port 80!
Here are some links that I collected during my R&D
Railo Web Socket Extention
Railo Proxy ignoring static resources
- https://github.com/getrailo/railo/wiki/Installation-nginx
- http://www.silverink.nl/nginx-reverse-proxy-rail/
- http://www.silverink.nl/splitting-static-dynamic-traffic-nginx-railo/
- http://www.phoenixvps.com/guides/2013/04/nginx-configuration-examples
Websocket Proxy
- http://nginx.org/en/docs/http/websocket.html
- http://siriux.net/2013/06/nginx-and-websockets/ - 3. WSS Proxy with Path Rewriting
significant part of nginx.conf
server {
listen 80;
server_name dev.local;
index index.cfm index.html;
root C:\Inetpub\websites\dev.locsl\webroot;
location / {
try_files $uri $uri/ @farcry;
}
location /webtop {
alias C:\Inetpub\websites\dev.local\webroot\farcry\core\webtop;
try_files $uri $uri/;
}
location @farcry {
rewrite ^/(.*)? /index.cfm?furl=$1 last;
}
location ~* \.(cfm|cfml|cfc|jsp|cfr)(.*)$ {
proxy_pass http://dev.local:8888;
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_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
# Tomcat Server.xml :
# <Valve className="org.apache.catalina.valves.RemoteIpValve" />
}
#### Web Sockets
## old JS
## ws = new WebSocket('ws://dev.local:10126');
## new JS
## ws = new WebSocket('ws://dev.local:80/stock');
location /stocks {
access_log off;
proxy_pass http://dev.local:10126;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Path rewriting
rewrite /stocks/(.*) /$1 break;
proxy_redirect off;
}
location /chat {
access_log off;
proxy_pass http://dev.local:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Path rewriting
rewrite /chat/(.*) /$1 break;
proxy_redirect off;
}
}