Reputation: 2880
[Meta notes: the following question is not answered, but the problem that the question is involved in is considered solved. Thanks to @georgek]
I am experimenting Noir
web framework on a home machine running Ubuntu linux. I followed the "Getting started"
part from the Noir site and got the demo server up and running. But that example was running at the testing port 8080
. I wanted it to run at the default http port (port 80), so I edited the "8080"
part of the clojure file my-website/src/my_website/server.clj
:
(ns my-website.server
(:require [noir.server :as server]))
(server/load-views "src/my_website/views/")
(defn -main [& m]
(let [mode (keyword (or (first m) :dev))
port (Integer. (get (System/getenv) "PORT" "80"))] ; <- I changed "8080" to "80"
(server/start port {:mode mode
:ns 'my-website})))
And tried to run the demo again, but I got the following:
$ lein run
Starting server...
2011-11-27 13:26:27.183:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
2011-11-27 13:26:27.189:INFO::jetty-6.1.25
2011-11-27 13:26:27.242:WARN::failed [email protected]:80: java.net.BindException: Permission denied
2011-11-27 13:26:27.242:WARN::failed Server@111ded2: java.net.BindException: Permission denied
Exception in thread "main" java.lang.RuntimeException: java.net.BindException: Permission denied
at clojure.lang.Util.runtimeException(Util.java:165)
at clojure.lang.Compiler.eval(Compiler.java:6476)
at clojure.lang.Compiler.eval(Compiler.java:6455)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
...
...
I have root access to the machine, I just don't know where to start to solve this problem. Could anybody help?
What I have tried:
I tried to run lein run
as su
, but it didn't work either.
I stopped the Apache2 server for releasing port 80 (Is this the right way to do it?):
$ sudo /etc/init.d/apache2 stop
Still doesn't work.
I did it all over again on a macbook, it worked for port 80 ("sudo" is needed). Don't know why it doesn't work for Ubuntu.
The solution that I took
A practical solution to the problem (not an answer to the question):
I followed this
web page, and used 8080 port as a service, and then configured the "httpd.conf" file of the Apache2 server to let port 8080 listen all the requests to port 80. This solution is provided by @georgek .
[I am sorry if this post is not valuable to some people, I'm new in this field. Thank you again everyone!]
An alternative solution
@ivant provides an alternative solution which also works!
Upvotes: 1
Views: 1380
Reputation: 3919
There is also privbind and authbind, which grant the privilege to bind to low ports (< 1024) to non-root apps. They are both available in ubuntu and may be a viable alternative to apache, especially while developing. To install (both) use the following:
$ sudo apt-get install privbind authbind
and check the man pages for usage instructions.
P.S. I know I'm a bit late for the party, but thought that these might still be useful.
Upvotes: 2
Reputation: 877
I would recommend running Noir as a non-root user on 8080 and using a rule to forward that domain and port to your Apache running on 80. Is there another reason you don't want to do that?
Upvotes: 2
Reputation: 19203
Only root can use ports lower than 1024. If you say you tried running it as root or with sudo and still didn't work then most probably port 80 is already in use by some other application.
LE: This should show you which process is using the port 80
ps -eo pid,user,group,args,etime,lstart | grep `lsof -i :80 | grep LISTEN | head -1 | cut -f4 -d' '`
Upvotes: 4