Simple Invoices PDF Export Formatting and Logo Missing – NGinx

Written by James McDonald

March 5, 2014

I am running Simple Invoices on Nginx.

I have basic authentication switched on:

 location /simple_invoices/ {
    auth_basic  "Simple Invoices";
    auth_basic_user_file /etc/nginx/auth/htpasswd;
  }

The problem I have been seeing is that the formatting and the Logo is missing from my exported PDFs

simple_invoices_basic_auth_logo_missing

Examining the nginx access log I’m seeing 401 “Unauthorized” errors

192.168.0.1 - - [05/Mar/2014:00:00:21 +0000] "HEAD /simple_invoices/templates/invoices/default/style.css HTTP/1.1" 401 0 "http://example.com/simple_invoices/templates/invoices/default/style.css" "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7) Gecko/20040803 Firefox/0.9.3"
192.168.0.1 - - [05/Mar/2014:00:00:21 +0000] "GET /simple_invoices/templates/invoices/default/style.css HTTP/1.0" 401 188 "-" "-"
192.168.0.1 - - [05/Mar/2014:00:00:22 +0000] "HEAD /simple_invoices/templates/invoices/logos/logo.png HTTP/1.1" 401 0 "http://example.com/simple_invoices/templates/invoices/logos/jmits-logo.png" "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7) Gecko/20040803 Firefox/0.9.3"
192.168.0.1 - - [05/Mar/2014:00:00:22 +0000] "GET /simple_invoices/templates/invoices/logos/logo.png HTTP/1.0" 401 188 "-" "-"

The cause

The Simple Invoices application is making a web request to a basic authentication protected location and because it isn’t aware it has to authenticate, it is receiving an Access Denied. So the CSS and logo cannot be applied to the PDF

The fix

On the Web Server hosting your Simple Invoices installation edit the /etc/hosts file and add an entry for the server name or domain you access simple invoices with pointing to the loop back address (127.0.0.1)

e.g.

# if you access your simple invoices with
# http://example.com/simple_invoices/
127.0.0.1    example.com
# or for http://server.example.com/simple_invoices/
127.0.0.1    server.example.com

The above entry will cause the Simple Invoices to access the CSS and logo via the loopback IP

Next white list the loopback IP as allowed in the NGINX configuration file.

  location /simple_invoices/ {
    satisfy any;
    allow 127.0.0.1;
    deny all;
    auth_basic  "Simple Invoices";
    auth_basic_user_file /etc/nginx/auth/htpasswd;
  }

## run this at a command prompt to pick up the change
# service nginx reload

With these changes the logs now show that the resources need by the Simple Invoices PDF Export and Send via email are now working. Notice the return code of 200 idicating a successful request and that the request is from the loopback address of 127.0.0.1

127.0.0.1 - - [05/Mar/2014:00:26:39 +0000] "GET /simple_invoices/templates/invoices/default/style.css HTTP/1.0" 200 965 "-" "-"
127.0.0.1 - - [05/Mar/2014:00:26:39 +0000] "GET /simple_invoices/templates/invoices/logos/jmits-logo.png HTTP/1.0" 200 6897 "-" "-"
192.168.0.1 - jmcd [05/Mar/2014:00:26:45 +0000] "GET /simple_invoices/index.php?module=export&view=invoice&id=3&format=pdf HTTP/1.1" 200 542737 "http://example.com/simple_invoices/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"

With the result being a nicely formatted PDF

simple_invoices_basic_auth_logo_restored

 

References:

Nginx bypass basic authentication

Simple Invoice Missing Logo

1 Comment

  1. Philippe

    Thanks a lot for this post. I was having the same issue on my server. I didn’t have the access denied like you but adding the server name in the hosts files fixed it!

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Clear HSTS Settings in CHrome

Open chrome://net-internals/#hsts enter the domain in the query field and click Query to confirm it has HSTS settings...

Ubuntu on Hyper-v

It boils town to installing linux-azure # as root or sudo apt-get update apt-get install linux-azure...