Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NGinx -> TorqueBox
/etc/hosts:
127.0.0.1 myhost jboss_server
NGINX:
server {
listen myhost:80;
server_name myhost;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://rails1:8080;
}
}
TEST
Starting JBoss:
$ $TORQUEBOX_HOME/jboss/run.sh -c web -b jboss_server
$ elinks http://jboss_server:8080
returns error404, but it is fine because I removed root.war file
$ elinks http://rails1:8080
works fine, it opens Ruby on Rails application
$ elinks http://myhost
returns error404.
It looks like Nginx has some issues with reverse proxy
because the same rule for APACHE WORKS FINE.
<VirtualHost *:80>
ServerName myhost
DocumentRoot /path/to/rails1/public
ProxyPass / http://rails1:8080/
ProxyPassReverse / http://rails1:8080/
</VirtualHost>
SOLUTION
To duplicate Apache behavior, Nginx need few additional HTTP headers:
server {
listen myhost:80;
server_name myhost;
location / {
root /path/to/rails1/public;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://rails1:8080;
}
}
(It was also added to http://wiki.nginx.org/NginxLikeApache)
@nurettin
Copy link

nurettin commented Mar 1, 2013

Nowadays even this barebones nginx.conf works.

events {

}

http {
  upstream torquebox {
    server 127.0.0.1:8080;
  }

  server {
    location / {
      proxy_pass http://torquebox;
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment