Jihaisse
Jihaisse

Reputation: 977

How to serve static file with nginx

I'm switch from Apache to Nginx, and with apache all static files (images, css, javascript) in skins folders were served by Apache directly.

Example :

DocumentRoot    /zope/z_france_velo_tourisme/france-velo-tourisme/src
RewriteRule  ^/images-fvt/(.*) /fvt.commun/fvt/commun/skins/fvt_commun_images/images-fvt/$1 [L]

I read some docs about Nginx and Plone, and I didn't saw that. Here the example from Plone.org conf : https://github.com/plone/plone-org-nginx/blob/master/nginx.conf

So, my question is : is it still a good practice to serve static files with Apache/Nginx, and if yes, how to do it with Nginx ?

I've tried a configuration like this, but it didn't work, I get a 404 error :

root /zope/z_france_velo_tourisme/france-velo-tourisme/src;
rewrite ^/images-fvt/(.*)$ /fvt.commun/fvt/commun/skins/fvt_commun_images/images-fvt/$1;

I've also tried this (to avoid the root directive) but got a 404 too :

rewrite ^/images-fvt/(.*)$ /zope/z_france_velo_tourisme/france-velo-tourisme/src/fvt.commun/fvt/commun/skins/fvt_commun_images/images-fvt/$1;

Thanks.

Upvotes: 1

Views: 2116

Answers (2)

SteveM
SteveM

Reputation: 6048

Let me focus on what I think is the core of your question: "is it still a good practice to serve static files with Apache/Nginx ... ?"

Assuming that you're using a proxy caching mechanism, this is usually going to be a wasted optimization that just adds complexity to your configuration.

Instead, first visit your site setup and turn on appropriate http caching. Even the minimum settings will cause static resources to be served with headers calling for long expiration times. Under normal circumstances, this will mean that your zope/plone instance only serves a static resource very infrequently.

Either set up proxy caching inside Nginx or -- if you need serious performance -- set up Varnish. Or, use a caching CDN like Cloudflare.

The benefits you'll get out of spending time implementing caching will likely vastly outweigh any benefits you'd see from setting up an alternative static file mechanism.

Upvotes: 3

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42899

server {
    listen 433 ssl;
    server_name plone.org

    root /path/to/virtual/server/folder;
    location / {
        proxy_pass http://whatever;
    }
    location ~^ (images|css|js|anything)/ {

    }
}

something like this should work, if you have the assets in the right place.

Upvotes: 2

Related Questions