How to make jetty server (ring.adapter.jetty) accessible from external hosts - clojure

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 :)

Related

Django access from outside VMWARE (Public access)

I'm using Django 3.0.5 under Kalilinux2020.1 launched from a virtual machine on VMWARE ESXI.
I want to make my project public but it's not working.
I modified the settings.py and add :
ALLOWED_HOSTS = ['*']
The django server is launched using
pyhton3 manage.py runserver 0.0.0.0:8080
I allowed the port 8080 in the firewall using
firewall-cmd --zone=public --add-port=8080/tcp
and I forwarded the port 8080 in the router
P.S: I can access to my server from the other machines in the VMWare (LAN) but i can't get access from outside.
Anyone has faced this problem?
The network adapter in your VM, it should be either Brigde or NAT either way it can't be accessible other hosts
I just find out the solution,
I changed the port to be forwarded from 8080 to 9001 and it works like charm now.
Thank you.

How can I make lein ring / jetty server accessible externally?

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

Vagrant with xdebug can't connect to host

My vagrant setup for the network is config.vm.network :private_network, ip: "192.168.56.101". If I'm accessing a php page with echo $_SERVER['REMOTE_ADDR']; I got 192.168.56.1 as result. The problem now is that I can't ping 192.168.56.1, so also the config for Xdebug with xdebug.remote_connect_back=1 will fail, because Xdebug tries to connect to 192.168.56.1. If I use my normal ip address with xdebug.remote_host=X.X.X.X everything works fine, but I want to use xdebug.remote_connect_back=1. What can I do that it will work?
I was having the same problem and then started up a Virtualbox manually and realized that I hadn't started a virtualbox since updating and the firewall had to updated. Once I restarted virtualbox I could ping 192.168.56.1 and not have to rely on a hard coded ip address. So, my guess, is that you probably have firewall issues.

How to locally test Django project accessing it using example.com domain?

I'm willing to test Django project, but I want to access it using “example.com“. Before I used “127.0.0.1:8000“ (manage.py runserver), but now I have need to test how my project acts on different TLDs. All I want to do is somehow tell my computer that “example.com“ points to “127.0.0.1:8000“. I don't want others to have access to it, so it's not question about deployment.
I am Linux user. Any help would be much appreciated!
sudo vi /etc/hosts and add the following line at the end.
127.0.0.1 example.com
Also, if you run the web server as root, you can use port 80 and not have to type example.com:8000 into the address bar.
change the hosts file at /etc/hosts
Just edit /etc/hosts so that example.com maps to that 127.0.0.1.
I don't think you can map it to a specific port number though, so you'll need to either access example.com:8000 or run the server on port 80 (probably via sudo).
Simple, edit your hosts file at /etc/hosts so that your site "example.com" maps to the localhost "127.0.0.1"

Connecting to EC2 Django development Server

I am new to EC2 and web development. Currently I have a Linux EC2 instance running, and have installed Django. I am creating a test project before I start on my real project and tried running a Django test server.
This is my output in the shell:
python manage.py runserver ec2-###-##-##-##.compute-1.amazonaws.com:8000
Validating models...
0 errors found
Django version 1.3, using settings 'testsite.settings'
Development server is running at http://ec2-###-##-##-##.compute-1.amazonaws.com:8000/
Quit the server with CONTROL-C.
To test that it is wroking I have tried visiting: ec2-###-##-##-##.compute-1.amazonaws.com:8000 but I always get a "Cannot connect" message from my browser.
Whenever I do this lcoally on my computer however I do successfully get to the DJango development home page at 127.0.0.1:8000. Could someone help me figure out what I am doing wrong / might be missing when I am doing this on my EC2 instance as opposed to my own laptop?
Using an ec-2 instance with Ubuntu, I found that specifying 0.0.0.0:8000 worked:
$python manage.py runserver 0.0.0.0:8000
Of course 8000 does need to be opened for TCP in your security group settings.
You probably don't have port 8000 open on the firewall. Check which security group your instance is running (probably "default") and check the rules it is running. You will probably find that port 8000 is not listed.
1) You need to make sure port 8000 is added as a Custom TCP Rule into your Security Group list of inbound ports
2) Odds are that the IP that you see listed on your AWS Console, which is associated to your instance is a PUBLIC IP OR a PUBLIC Domain Name(i.e. ec2-###-##-##-##.compute-1.amazonaws.com or 174.101.122.132) that Amazon assigns.
2.1) If it is a public IP, then your instance has no way of knowing what the Public IP assigned to it is, rather it will only know the its assigned Local IP.
2.2) To get your Local IP on a Linux System, type:
$ ifconfig
Then look at the eth0 Data and you'll see an IP next to "inet addr" of the format xxx.xxx.xxx.xxx (e.g. 10.10.12.135) This is your Local IP
3) To successfully runserver you can do one of the following two:
$ python manage.py runserver <LOCAL IP>:8000
or
$ python manage.py runserver 0.0.0.0:8000
** Option Two also works great as Ernest Ezis mentioned in his answer.
EDIT : From The Django Book : "The IP address 0.0.0.0 tells the server to listen on any network interface"
** My theory of Public IP could be wrong, since I'm not sure how Amazon assigns IPs. I'd appreciate being corrected.
I was having the same problem. But I was running RHEL on EC2. Besides from adding a rule to security group, I had to manually add a port to firewalld.
firewall-cmd --permanent --add-port=8000/tcp
firewall-cmd --reload
That worked for me! (Although no idea why I had to do that)
Yes, if you use quick launch EC2 option, you should add new HTTP rule (just as it appears on the list) to run a development server.
Adding a security group with the inbound rules as follows usually does the trick unless you have something else misconfigured. The port range specifies which port you want to allow incoming traffic on.
HTTP access would need 80
HTTP access over port 8000 would need 8000
SSH to server would need 22
HTTPS would need 443