Why isnt hunchentoot serving my images on ec2 AWS?

55 views Asked by At

I have deployed a hunchentoot sever on an aws ec2 instance and everything is working well but my images only render locally ie localhost but when is up and running on the ec2 instance i get a 404 error associated with the images.

I have in the same directory the file server.lisp and the directory static/ where my images are.

on server.lisp i have this code:

(define-easy-handler (lisp-handler :uri "/lispy") ()
  (setf (hunchentoot:content-type*) "image/png")
  (setf (header-out "Access-Control-Allow-Methods") "GET, OPTIONS")
  (setf (header-out "Access-Control-Allow-Headers") "Content-Type")
  (setf (header-out "Access-Control-Allow-Origin") "http://myhomepage.info, http://localhost:4243")
  (handle-static-file "static/lisp.png"))

(define-easy-handler (sicp-handler :uri "/wizard") ()
  (setf (hunchentoot:content-type*) "image/jpg")
  (setf (header-out "Access-Control-Allow-Methods") "GET, OPTIONS")
  (setf (header-out "Access-Control-Allow-Headers") "Content-Type")
  (setf (header-out "Access-Control-Allow-Origin") "http://myhomepage.info, http://localhost:4243")
    (handle-static-file "static/sicp.jpg"))

(hunchentoot:define-easy-handler (index :uri "/") ()
  (setf (hunchentoot:content-type*) "text/html")
    (format nil 
        "<!doctype html>
<html>
<head>
 <meta charset=\"UTF-8\">
    <title>Jobs Compilers</title>
</head>
<body>
<h3> ..</h3>
<p><img src=\"http://myhomepage.info/wizard\"  alt=\"wiz\" width=\"300\" height=\"300\" align=\"left\">....<img src=\"http://myhomepage.info/lispy\" alt=\"lispy\" width=\"300\" height=\"300\" align=\"right\">
<hr />
</body>
</html>"))
(defvar *server*
  (make-instance 'hunchentoot:easy-acceptor
                 :port 4243
         :document-root #p"static"))

Im not quite sure why this is happening. as i said it works on localhost:4243 but when i deploy it it doesnt work.

I already check the permissions for the static dir on my ec2 instance and everything looks good. so I am not sure.

Does anybody have any pointers?

1

There are 1 answers

0
coredump On

The default listening :address is "127.0.0.1", you probably need to give the address associated with the network interface that is accessible from the outside.

Generally people also use nginx as a gateway, in which case you can serve your webpages on the local network only, and nginx will pass requests to your server. But here I guess AWS is doing the work of the gateway.

May be related: Amazon EC2 instance through public ip is not working