Welcome! Log In Create A New Profile

Advanced

Nginx as reverse proxy for Jetty

Stefan Scott
November 18, 2010 05:52PM
Hi -

I need some help configuring nginx as a proxy in front of Jetty (on
Debian).

Jetty is serving my Java web app correctly, because if I test it with
this lengthier alternate notation (which I also used before setting up
the nginx proxy), the Java web app login page appears and I can log in:

http://myhost.com:8080/testapp001.com


But when I do the following:

http://testapp001.com


I get the error message:

403 Forbidden
nginx/0.8.53



Here's my nginx.conf and testapp001.com.xml files

# This file is /etc/nginx/sites-available/testapp001.com
# Source: http://wiki.nginx.org/JavaServers

server {
listen 80;
server_name .testapp001.com;
access_log /var/log/www/testapp001.com/access.log;
error_log /var/log/www/testapp001.com/error.log;

root /opt/jetty/webapps/testapp001.com;

location / {
index index.jsp;
}

location ~ \.do$ {
proxy_pass http://localhost:8080;
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;
}
location ~ \.jsp$ {
proxy_pass http://localhost:8080;
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;
}
location ^~/servlets/* {
proxy_pass http://localhost:8080;
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;
}
}


The Java web app's WAR file has been decompressed to create this
directory:

/opt/jetty/webapps/testapp001.com


Here is file /opt/jetty/etc/testapp001.com.xml:

# Source: http://wiki.nginx.org/JavaServers

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="configurationClasses">
<Array type="java.lang.String">
<Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
<Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
<Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>
</Set>
<Set name="contextPath">/</Set>
<Set name="resourceBase"><SystemProperty name="jetty.home"
default="."/>/webapps/testapp001.com</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>testapp001.com</Item>
</Array>
</Set>

</Configure>



This file is /opt/nginx/conf/nginx.conf - the correct symlink was also
created previously by doing:

sudo ln -s /etc/nginx/sites-available/testapp001.com
/etc/nginx/sites-enabled


worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/sites-enabled/*;
}


Here are last the 2 lines of the nginx log files:

#This is file /var/log/www/testapp001.com/access.log

999.999.999.999 - - [18/Nov/2010:19:17:23 -0200] "GET / HTTP/1.1" 403
571 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)
AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7"

999.999.999.999 - - [18/Nov/2010:19:17:32 -0200] "GET /favicon.ico
HTTP/1.1" 404 571 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)
AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7"



#This is file /var/log/www/testapp001.com/error.log

2010/11/18 19:17:23 [error] 13319#0: *3 directory index of
"/opt/jetty/webapps/testapp001.com/" is forbidden, client:
999.999.999.999, server: testapp001.com, request: "GET / HTTP/1.1",
host: "testapp001.com"

2010/11/18 19:17:32 [error] 13319#0: *3 open()
"/opt/jetty/webapps/testapp001.com/favicon.ico" failed (2: No such file
or directory), client: 999.999.999.999, server: testapp001.com, request:
"GET /favicon.ico HTTP/1.1", host: "testapp001.com"


(I have substituted "999.999.999.999" above instead of my client
machine's IP address. :-)

I have also tested setting the owner:group of directory

/opt/jetty/www/webapps/testapp001.com


three different ways:

cd /opt/jetty/www/webapps
sudo chown -R jetty:jetty testapp001.com
sudo chown -R root:root testapp001.com
sudo chown -R www-data:root testapp001.com


But navigating to 'http://testapp001.com' still gives the error message
"403 - Forbidden"

Navigating to 'http://myhost.com:8080/testapp001.com' correctly displays
the login page of the Java web app and lets me log in successfully - so
Jetty and the web app are working - I just can't get the nginx reverse
proxy configured properly.

Thanks for any help!

--
Posted via http://www.ruby-forum.com/.

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Nginx as reverse proxy for Jetty

Stefan Scott November 18, 2010 05:52PM

Re: Nginx as reverse proxy for Jetty

Martin November 23, 2010 05:28AM

Re: Nginx as reverse proxy for Jetty

Maxim Dounin November 23, 2010 06:56AM

Re: Nginx as reverse proxy for Jetty

Martin November 23, 2010 08:10AM

Re: Nginx as reverse proxy for Jetty

Maxim Dounin November 23, 2010 10:48AM

Re: Nginx as reverse proxy for Jetty

Martin November 23, 2010 08:14AM

Re: Nginx as reverse proxy for Jetty

Martin November 24, 2010 03:12AM

Re: Nginx as reverse proxy for Jetty

Maxim Dounin November 24, 2010 05:48AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 77
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready