Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Mojolicious-Hypnotoad-Nginx - rendering images

by perlfan (Vicar)
on Apr 15, 2021 at 17:09 UTC ( [id://11131336]=note: print w/replies, xml ) Need Help??


in reply to Mojolicious-Hypnotoad-Nginx - rendering images

Sounds like the browser is taking your /tree.png, and is sending something to the server that makes the handler unable to determine that you, in fact, want a static resource.

Replies are listed 'Best First'.
Re^2: Mojolicious-Hypnotoad-Nginx - rendering images
by haukex (Archbishop) on Apr 15, 2021 at 18:23 UTC
    Sounds like the browser is taking your /tree.png, and is sending something to the server that makes the handler unable to determine that you, in fact, want a static resource.

    OP mentions favicon.ico not working, which Mojolicious has built-in, so even if ngnix is routing requests for static files to Mojo, at least that should work. (Unless there's something else OP isn't telling us.)

Re^2: Mojolicious-Hypnotoad-Nginx - rendering images
by pdkakoba (Novice) on Apr 16, 2021 at 16:00 UTC

    Yes, indeed, a 'static' file handler is needed but failing to implement one.

    The setup briefly is as follows: Debian10 on a Linode, running Perl 5.28 and Mojolicious 9.17

    The simple_app was setup automatically with 'mojo' and in the simple_image.yml, one directive was added:
    hypnotoad: proxy: - 1

    The tree.png appears in the Welcome page (with the favicon.ico), when runs directly under 'daemon' server. The hypnotoad server was set-up as a systemd service with the most recent Nginx configuration as:

    upstream backendurl { server 127.0.0.1:8080 fail_timeout=0; } server { listen 80; listen [::]:80; server_name example.com www.example.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log info; root /var/www/simple_image/public; location / { try_files $uri @proxy; access_log off; expires max; add_header 'Access-Control-Allow-Origin' 'http://example.com'; } location @proxy { proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://backendurl; } }
    The default simple_image app runs properly but without rendering the tree.png image nor the favicon. When this url is enter: http://example.com/tree.png - the image alone appears together with the favicon.

      Success was found with an Apache2 setup with mod_proxy, mod_proxy_http, mod_headers and inspired from these two presentations: https://github.com/mojolicious/mojo/wiki/Apache-deployment
      https://stackoverflow.com/questions/23571608/configure-urls-with-prefix-in-mojolicious-behind-reverse-proxy-proxypass

      1) The image reference remained as:  <img src="/tree.png" alt="tree">
      2) using this configuration in Apache2 (version:2.4.38):

      ServerName example.com <Proxy *> Require all granted </Proxy> ProxyPass /static ! ProxyPass /favicon.ico ! ProxyRequests Off ProxyPreserveHost On ProxyPass /echo ws://localhost:8080/echo ProxyPass / http://localhost:8080/ keepalive=On ProxyPassReverse / http://localhost:8080/ RequestHeader unset X-Forwarded-Host RequestHeader set X-Forwarded-Proto "http"

      Result renders both the tree image and the custom favicon on both pages.
      Does that above give insight into seeking a Nginx solution?

      The above Apache2 solution gave hint to a successful Nginx solution as follows:
      upstream backendurl { server 127.0.0.1:8080 fail_timeout=0; } server { listen 443 ssl; listen [::]:443 ssl; server_name myexample.com www.myexample.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log info; root /home/sammy/simple_image/public; location / { try_files $uri @proxy; access_log off; expires max; add_header 'Access-Control-Allow-Origin' 'https://myexample.com'; } location /static { try_files $uri @proxy; access_log off; expires max; add_header 'Access-Control-Allow-Origin' 'https://myexample.com'; } location @proxy { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://backendurl; } ssl_prefer_server_ciphers on; #add all the necessary ssl files, (eg .crt and key files) and li +nks here }
      Postscript 22-May-2021: The problem appeared to be with the install of iRedmail (a popular mailserver setup) on the same server. Recently the application was revised to 1.4.0 version. After rebuilding the server with the updated iRedmail app, the published Mojolicious deployment code worked successfully.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131336]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-29 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found