Marcus
Marcus

Reputation: 5143

On OSX, Instead of localhost:8090 how can I use just localhost with Jetty?

I use an external API where a domain/key-pair is needed, and the domain-name doesn't tolerate the port. So for my local development environment I would need to be able to use an URL without the port. I'm using Jetty.

Any ideas if / how this can be achieved?

Upvotes: 0

Views: 2608

Answers (2)

Tim
Tim

Reputation: 6509

(Some of what I'm writing might be obvious to you, but I prefer to be explicit)

When you say you want to have a URL without the port, that means that you actually want to run on port 80.

When a URL doesn't include a port, the default port for the scheme is implied. The default port for http is 80, so http://www.google.com/ is the same as http://www.google.com:80/

So, to have your Jetty server available at http://localhost/, you need to have it accessible on port 80.

There are 3 broad options:

  1. Actually start it on port 80. However, on most operating systems only the admin (root) user can start services on ports lower than 1024, so you would need to start/run jetty as root. On OSX, that can be done by running Jetty with sudo. There are more complicated ways of doing this, but if you're just running on your own desktop sudo is the easiest. You can read about some of the other ways here: http://wiki.eclipse.org/Jetty/Howto/Port80

  2. Use operating system features to map requests for port 80 to the port you're running Jetty on. On Linux (and other similar operating systems) you can use ipchains or iptables (the Port80 page I listed above describes these), on Mac OSX ipfw can do the sme thing. Here's an example for running Tomcat on port 80 on OSX, exactly the same instructions will work for Jetty - In your case just change the 8080 to 8090.

  3. Put another server (like Apache HTTPd) in front of Jetty. Run that server on port 80, and configure it to proxy requests through to your Jetty server. See: http://wiki.eclipse.org/Jetty/Howto/Configure_mod_proxy

Option #2 is probably what you want, but you'll need to decide for yourself.

Upvotes: 1

sethcall
sethcall

Reputation: 2897

According to this document which I just found on the Jetty website, you can configure ports in jetty.xml:

Then googling 'jetty.xml port' led me to this page (because I wanted a syntax example): Howto/Configure Jetty,

which had one, but also led me to this command-line usage where they specify the port from command line when starting Jetty:

java -Djetty.port=80 -jar start.jar etc/jetty.xml

Upvotes: 1

Related Questions