Trouble with configuring ports

214 views
Skip to first unread message

Dylan Halperin

unread,
Apr 24, 2012, 9:39:07 PM4/24/12
to lif...@googlegroups.com
Hello all,
I'm currently trying to set up my lift app on port 80, with the future goal of port forwarding it and making it available to the world, but I've hit a snag..

(here's an excerpt from my build.sbt)

libraryDependencies ++= Seq(
  "org.mortbay.jetty" % "jetty" % "6.1.22" % "container",
   ...
)

port in container.Configuration := 80

With that configuration, I can access my app from  http://localhost/ but not from http://192.168.0.23/ (my local IP)

It I omit the line that sets the port to 80, it defaults to 8080.  In that case, I can access my app from both http://192.168.0.23:8080/ and http://localhost:8080/ 

Is this a lift thing? Am I missing some important configuration step that allows me to put the app on port 80? Beyond that, I've tried messing with my firewall to allow port 80 but I'm unsure of whether I did it right or not. Thank you for any help you can offer!

Diego Medina

unread,
Apr 24, 2012, 11:40:51 PM4/24/12
to lif...@googlegroups.com
If you don't get any answer here, you may want to try the sbt mailing list at:
https://groups.google.com/forum/?fromgroups#!forum/simple-build-tool
Changing the port is an sbt thing more than a Lift thing.
But note that this will only affect your jetty instance while running
on sbt, which is not recommended once you go to production.
Once you go on production, you should install jetty on your server and
deploy Lift as a WAR file. In that case, you would go into the jetty
ocnfig files to set the right port.

Regards,

Diego

> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code

--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Olek Swirski

unread,
Apr 25, 2012, 4:26:58 AM4/25/12
to lif...@googlegroups.com
yep, you need to get jetty standalone, extract it and set up
the port there. use 8080 for testing, it makes no sense
to change that in development. you can also set up standalone
jetty locally, and then use 80.

with standalone jetty extracted you set up the port here:
jetty-inst-dir/etc/jetty.xml
<Set name="port"><Property name="jetty.port" default="80"/></Set>

one important thing, is to pass proper startup parameters when
you start jetty, for example on linux this works fine for me

/usr/lib/jvm/java-6-sun/bin/java -Djetty.home=/home/olek/dev/jetty
-Djava.io.tmpdir=/tmp -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled
-Xms256m -Xmx256m -Xmn64m -Xss2m -jar /home/olo/dev/jetty/start.jar &;
sleep 40; disown %1;

although you may give higher values (these values are adjusted to my
server, which has not that much of it)

then you deploy war into webapps directory
also you need to create (from default sample) file for each webapp in
contexts dir, for example contexts/my_app.xml

still best set up in my opinion is to use iptables to set up firewall
on all unused ports, and use nginx as reverse proxy, and only
through nginx resolve webapps to jetty, leaving jetty on 8080
(opened only locally) and nginx on 80. however nginx configuration
is another story.

Olek Swirski

unread,
Apr 25, 2012, 4:35:15 AM4/25/12
to lif...@googlegroups.com
sorry, small mistake with startup params, should be:

/usr/lib/jvm/java-6-sun/bin/java -Djetty.home=/home/olek/dev/jetty
-Djava.io.tmpdir=/tmp -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled
-Xms256m -Xmx256m -Xmn64m -Xss2m -jar /home/olek/dev/jetty/start.jar &;
sleep 40; disown %1;

adjust /home/olek/dev/jetty so that it points to your jetty dir
I have a small virtual machine with 768MB - Debian running on
Xen full root controll. great to try out things or to host site
so I can recommend using http://bettervps.net ,but linux
experience is needed to handle that (I took the route of
learning by doing :)


On 25/04/12 05:40, Diego Medina wrote:

Olek Swirski

unread,
Apr 25, 2012, 4:39:10 AM4/25/12
to lif...@googlegroups.com
one more thing
/usr/lib/jvm/java-6-sun/bin/java should of course point to
your java executable. you can use openjdk instead, I
use openjdk-7 on another machine and it works fine.

Olek Swirski

unread,
Apr 25, 2012, 8:47:41 AM4/25/12
to lif...@googlegroups.com
I was looking at some older topics, and I think
this may be usefull in what you want to achieve
among other things it also deals with changing the
jetty default port to 8081. Topic title on this mailing list is:
Using SSL during development

and some relevant code here
https://github.com/siasia/xsbt-web-plugin/wiki/Settings

So I guess you should be able to adapt it to make
sbt jetty plugin use port number 80

Dylan Halperin

unread,
Apr 26, 2012, 11:42:48 PM4/26/12
to lif...@googlegroups.com
Thanks for your replies! I followed your suggestion and set up jetty by itself, and changed the config to use port 80. Things are working now.. mostly..
 One of my pages has some comet on it, and after a while of sitting on that page, I start seeing errors in the console:

  23:31:22.789 [qtp1484678-13] ERROR net.liftweb.http.LiftRules - Exception being returned to browser when processing /comet_request/60249106562/1fi6ja9a1ksvz1g6d0wzaf6a4m/F1129226053831XHKP3Y: Message: java.lang.IllegalStateException: No uri
org.eclipse.jetty.server.Request.getServerName(Request.java:1014)
org.eclipse.jetty.server.Request.getServerPort(Request.java:1094)
net.liftweb.http.provider.servlet.HTTPRequestServlet.serverPort(HTTPRequestServlet.scala:92)
net.liftweb.http.Req$$anonfun$hostAndPath$1.apply(Req.scala:987)
net.liftweb.http.Req$$anonfun$hostAndPath$1.apply(Req.scala:987)
net.liftweb.common.Full.map(Box.scala:491)
net.liftweb.http.Req.hostAndPath(Req.scala:987)
net.liftweb.http.LiftSession$$anonfun$cometForHost$1.apply(LiftSession.scala:600)
net.liftweb.http.LiftSession$$anonfun$cometForHost$1.apply(LiftSession.scala:599)
scala.collection.TraversableLike$$anonfun$filter$1.apply(TraversableLike.scala:213)

A bit of googling didn't turn up anything obvious to me- what could be causing this?

(FWIW, this is a toy app, nothing fancy going on. (Also I'm on windows))

Olek Swirski

unread,
Apr 27, 2012, 2:25:33 AM4/27/12
to lif...@googlegroups.com
I think I've seen something similar, but I'm not very good with
comet. I guess this has something to do with clearing references to
functions used within a particular page using comet. but my knowledge
here is very sparse. surely one of the more knowledgeable people on
this mailing list will be able to answer this.
--

Diego Medina

unread,
Apr 27, 2012, 11:49:23 AM4/27/12
to lif...@googlegroups.com

Olek Swirski

unread,
Apr 29, 2012, 5:07:54 AM4/29/12
to lif...@googlegroups.com
one more thing about using jetty standalone
at some point you may want it to run your apps in production mode
and not development mode (which is used by jetty plugin in sbt)
to achieve that you may either change some global settings in /etc
under jetty dir or you may have a code like this in your Boot.scala
(then you may have different setting for each lift app running on
a single jetty instance)

import javax.servlet.FilterConfig
import net.liftweb.http.LiftFilter

class RunModeLiftFilter extends LiftFilter {
override def init(config: FilterConfig) {
System.setProperty("run.mode", "development")
super.init(config)
}
}

you put it just below the imports in Boot.scala, and then
can change run.mode to be development or production.
accordingly to this settings your app will read properties
from either default.props (development), or from
production.default.props (production). you can also
run.mode testing can also be used.

all the props files are in src/main/resources/props
using different props files for different run.mode
makes it easy to adjust for example database connection
details to either production or development conditions.
you may for example use in-memory h2 for development
and postgres or mysql for production

you may take a look at this example app which uses
this approach to set up db connections with squeryl
(it uses SchemaHelper from Peter Petersson's
squeryl example)

https://github.com/oolekk/sqrlrcrd.com
Reply all
Reply to author
Forward
0 new messages