[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 SocketConnector#0.0.0.0: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!
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' '`
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?
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.
Related
I have been having an issue with deploying to my website management service, after following a lot of information from various forums, I came to one that said by uninstalling and reinstalling the web deployment tool solved his problem, the problem is now that both of my websites are not reachable.
After running the following command in cmd...
netstat -aon | findstr 80
Its listening on the following..
TCP [::]:80 [::]:0 LISTENING 4
But no where in the listing do i find the following TCP 0.0.0.0:80
Any help would be greatly appreciated.
Mark.
Ok I solved this particular issue with the following command...
netsh http add iplisten ipaddress=0.0.0.0
:-)
I have two ember projects: project1, project 2
project1: ember s , port 4200 is working fine. I closed the project1 terminal and again tried to start ember s inside project2, when i do that, i am getting Port 4200 is already in use.
Port 4200 is already in use.
Why am i getting this error, as other instances where already killed and how to rectify it ?
Try the following,
sudo fuser -k 4200/tcp
It will kill all process belongs to port 4200.
None of the answers work on Mac so I'm posting this solution.
kill -9 $(lsof -i tcp:4200 -t)
I extended my comment as answer for windows user,
To see the 4200 is already in use or not, if so what process is holding port, run the below command
netstat -ano | findstr :4200
This will show some result like this,
TCP 0.0.0.0:4200 0.0.0.0:0 LISTENING 12784
TCP [::]:4200 [::]:0 LISTENING 12784
which will list out list of processes using 4200 port. you can find process id in the result. in the above result pid is 12784 . We need to kill this process to free port.
TaskKill.exe /F /PID 12784
The following solution works on Mac & Linux.
Try using:
ember serve --port 0
Per ember help: "Pass 0 to automatically pick an available port". (In a terminal, type ember help).
This approach can also work to run more than one ember site at the same time. It helps you find an available port as well as a different live-reload-port for each:
ember serve --port 0 --live-reload-port 0
If you get the same error in any of these cases, you can also enter the following python script at your Terminal prompt to identify an available port:
python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'
You can then specify ports you know to be available:
ember serve --port <known_port_1> --live-reload-port <known_port_2>
It's not really a solution, but I'm posting it anyway incase anyone suffers the same fate as me. All morning I've tried to boot an app on any port available, only to be met with No open port found above 0.
After a tonne of trial and error, what fixed it was rebooting the Mac. Even though it had only just done a fresh boot ¯\(ツ)/¯
UPDATE: it seems as though specifying a port and host in .ember-cli was affecting this. Oddly, if you specify the same values as command line arguments it works fine ¯_(ツ)_/¯
Using VirtualBox, I have a NAT enabled VM running Centos 7. The host OS is Windows 7. I can't seem to access the Django web server running inside the VM. What am I missing?
I have two port forwarding rules set for the Virtual Machine:
I start the Django web server on the guest OS with:
python manage.py runserver 0.0.0.0:8000
And I try to visit the webpage on the host OS at:
http://localhost:8000
Google Chrome gives me the error code ERR_CONNECTION_RESET.
The result of curl on the host OS:
[user#win7 ~ ]$ curl http://localhost:8000
curl: (56) Recv failure: Connection reset by peer
Here is the result of a netstat performed on the guest OS:
[user#vm ~ ]$ netstat -na | grep 8000
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN
Here is the result of a netstat performed on the host OS (with Cygwin):
[user#win7 ~ ]$ netstat -na | grep 8000
TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING
It is also worth mentioning that the SSH rule works. I can SSH into the machine with no problems.
This is not a solution, but a work-around for my problem. Maybe this will help anyone encountering a problem similar to mine, and just wants to be able to connect to their VM's webserver.
Since SSH was working, I figured I could access the webpage via a SSH Tunnel. The syntax for doing so via command line is:
ssh -L <local-port>:<remote-host>:<remote-port>
So in my situation, if I wanted to open a tunnel via command line I would do:
ssh -L 8000:127.0.0.1:8000
This would allow me to browse to http://localhost:8000 and access the website.
You can also do this via PuTTY, but I won't explain that here, so just Google for a guide.
The ssh tunnel is an OK work around, but the problem is almost certainly CentOS 7 which now uses firewalld rather than iptables to manager access. And, unlike iptables the default configuration is quite restrictive.
if
ps -ae | grep firewall
returns something like
602 ? 00:00:00 firewalld
your system is running firewalld, not iptables. They do not run together.
To correct your VM so you can access your django site from the host use the commands:
firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --reload
Many thanks to pablo v in the post "Access django server on virtual Machine" for pointing this out.
I'm currently attempting to start a project with Compojure.
At this point I am just trying to run the hello world app and see it through the browser.
I have a droplet on Digital Ocean with Ubuntu 13.04 installed and I cannot seem to access the webpage once the server is started.
lein ring server-headless 3000
eg: http://hostname:3000
I just get page not found. I checked to make sure jetty is using port 3000 and it is.
Am I missing dependencies?
I can't think of anything that would prevent me from viewing the page.
*Update: *
If I run the server on port 80 I can see it. I haven't added or configured any firewalls unless the Digital Ocean image comes with one by default.
on the instance run
sudo netstat -np | grep 3000
to see what address your server is listening to, if it is 0.0.0.0 then your server is listening to connections from any source and the problem is with an upstream firewall (most likely) or a local firewall (unlikely). If it is '127.0.0.1or::1/128` then your server is only listening for local connections and you need to change the binding address in the project.clj file, though this is unlikely as binding to any interface by default
I'm trying to run a web server using the following invocation
(run-jetty #'handler {:host "hostname" :port 8080})
This starts a server which I can access from the same host, but not externally. I am doing this on an EC2 instance and I use the internal IP of that machine as the "hostname", port 8080 is open for external access. I also tried using "0.0.0.0" as the hostname, but that resulted in the same behavior.
I'm using a slightly outdated version of ring-jetty-adapter (0.2.5) but I can't change that.
Any help is greatly appreciated!
to get access and keep it private you can run
ssh -L 8080:localhost:8080 your.ec2.instance
then open a browser to http://localhost:8080/myapp/
for your original question:
perhaps using the external ip or host name as "hostname" may help?
Just don't specify the :host option at all; Jetty seems to listen on all interfaces in that case. For example, I help with 4clojure. The webserver there is really running on port 8080 of the server raynes.me, with some nginx magic to forward port 80 if the host HTTP requests is 4clojure.com. You can access it directly if you like: http://raynes.me:8080 works fine, and here's our jetty call:
(run-jetty (var app) {:join? false :port 8080})
Thanks for your replies guys, it turns out that it was not a problem with jetty, I was running this on EC2, and had been applying port access permissions to a different security group than the one this particular instance belonged to :)