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. |