0

Using morbo, the static files are rendered for all pages. However with the hypnotoad server using Nginx as a proxy, a page is loaded but static files within are not rendered – not even the favicon, but calling a static html page within the same app, both images and favicon appear. What maybe missing?

   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/example.com/public;
 
  location / {
    try_files $uri @proxy;
    access_log off;
    expires max;
    add_header 'Access-Control-Allow-Origin' 'http://example.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;
  }
}
1
  • 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.
    – pdkakoba
    May 22, 2021 at 12:27

1 Answer 1

0

The Apache2 solution gave some hints: https://github.com/mojolicious/mojo/wiki/Apache-deployment
A successful Nginx solution was found 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 links here
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.