Serve Senaite with Nginx


#1

I would like to make my installation available to other users in the network. For that I setup an nginx server that reverse-proxies the requests to localhost:8080 where senaite runs. Though, the links that Senaite creates all start with localhost:8080. How can I tell Senaite that it runs on a different domain/port?

Cheers
Soren


#2

Hi @soerendip, you need to add a rewrite rule in NGINX, e.g.

server {
    [...]
    location / {
        proxy_set_header        Host            $http_host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        rewrite                 ^(.*)$ /VirtualHostBase/$scheme/$host/senaite/VirtualHostRoot/$1 break;
        proxy_pass              http://127.0.0.1:8080;
    }
}

Also see the official NGINX docs


#3

I tried that, but when I go to the server it returns:

<h2>Site Error</h2> <p>An error was encountered while publishing this resource. </p> <p><strong>Resource not found</strong></p> Sorry, the requested resource does not exist.<p>Check the URL and try again.</p><p><b>Resource:</b> senaite GET</p> <hr noshade=“noshade”/> <p>Troubleshooting Suggestions</p> <ul> <li>The URL may be incorrect.</li> <li>The parameters passed to this resource may be incorrect.</li> <li>A resource that this resource relies on may be encountering an error.</li> </ul> <p>For more detailed information about the error, please refer to the error log. </p> <p>If the error persists please contact the site maintainer. Thank you for your patience. </p>


#4

Probably your Senaite site does not call senaite?

Change this line according to your site ID:
rewrite ^(.*)$ /VirtualHostBase/$scheme/$host/<SENAITE-SITE-ID>/VirtualHostRoot/$1 break;


#5

I don’t understand what information I should put in there. What is SENAITE-SITE-ID standing for?? My domain? Interestingly, without the rewrite I can now access senaite, but the CSS does not work. And I get (blocked:mixed-content) for the css files. Probably, because I am serving via https.


#6

Oh, now it works. My configuration now looks like this:

location / {
    proxy_set_header        Host            $http_host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    rewrite                 ^(.*)$ /VirtualHostBase/$scheme/$host/lims/VirtualHostRoot/$1 break;
    proxy_pass              http://127.0.0.1:8080;

}

I had configured senaite so that it serves the LIMS under example.com/lims, though also pages as example.com/dashboard work fine. So, I am not sure why I have to put “lims” into the rewrite. I find this syntax not very intuitive and I am not sure what is going on and why it works. I would be glad if someone could give me an example.

Also, I am happy that it is working now, though I would like to serve senaite only at a certain folder. E.g. example.com/lims/… so that the senaite dashboard is shown under example.com/lims/dashboard.