Skip to content

Instantly share code, notes, and snippets.

@jcarley
Forked from hipertracker/gist:214210
Created May 1, 2012 18:32
Show Gist options
  • Save jcarley/2570296 to your computer and use it in GitHub Desktop.
Save jcarley/2570296 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment