Welcome! Log In Create A New Profile

Advanced

Configuring nginx proxy in front of Jetty

Posted by StefanScott 
Configuring nginx proxy in front of Jetty
November 18, 2010 03:47PM
Hi -

This is probably an easy question ... but it's my first time setting up nginx as a proxy in front of Jetty (on Debian), and I'm doing something wrong with my configuration.

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:
[code]
http://myhost.com:8080/testapp001.com
[/code]


But when I do the following:
[code]
http://testapp001.com
[/code]

I get the error message:
[code]
403 Forbidden
nginx/0.8.53
[/code]


Here's my nginx.conf and testapp001.com.xml files
[code]
# 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;

# Note: there is no file called /opt/jetty/webapps/testapp001.com/index.jsp on my system.
# So I was "suspicious" about this location directive below.
# I tried doing a test: I commented it out and restarted nginx and Jetty.
# But navigating to http://testapp001.com still gave the same error message "403 forbidden".

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;
}
}
[/code]

The Java web app's WAR file has been decompressed into a directory in:
[code]
/opt/jetty/webapps/testapp001.com
[/code]

[code]
# This file is /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>

# I commented this part out - because this Java web app actually does not use a database.
# <New id="YOUR_DB_NAME" class="org.mortbay.jetty.plus.naming.Resource">
# <Arg>jdbc/YOUR_DB_NAME</Arg>
# <Arg>
# <New class="org.postgresql.ds.PGConnectionPoolDataSource">
# <Set name="User">postgres</Set>
# <Set name="Password">*****</Set>
# <Set name="DatabaseName">YOUR_DB_NAME</Set>
# <Set name="ServerName">localhost</Set>
# <Set name="PortNumber">5432</Set>
# </New>
# </Arg>
# </New>

</Configure>
[/code]

[code]
# This file is /opt/nginx/conf/nginx.conf
# The correct symlink was also created previously:
# 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/*;
}[/code]

After I edit the above files, I do:
[code]
sudo /etc/init.d/nginx restart
sudo /etc/init.d/jetty restart
[/code]


Thanks for any help!



Edited 2 time(s). Last edit at 11/18/2010 03:50PM by StefanScott.
nginx log files
November 18, 2010 04:34PM
Here are last the 2 lines of the nginx log files:
[code]
#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"
[/code]

[code]
#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"
[/code]

(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
[code]
/opt/jetty/www/webapps/testapp001.com
[/code]

three different ways:
[code]
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
[/code]

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!



Edited 1 time(s). Last edit at 11/18/2010 04:43PM by StefanScott.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 161
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready