Smart compact vhost config for nginx Webserver as HTTPS-Proxy for Plone CMS

Nginx is one of the most used webserver/proxy in front of Plone CMS. This example showes how to setup a compact virtual host for Plone.

The following nginx vhost configuration applies to "derico.de" and "www.derico.de". And does a redirect for the non-www domain to the www-version.

The first too rewrites are taking care of the NON-WWW to WWW and HTTP to HTTPS redirects, by using only the host and server_name variables. This make it very easy to reuse for other vhosts.

The proxy_pass does the VirtualHostRoot rewriting and includes the Plone-site-id, which in this case is "Plone".

server {
    server_name www.derico.de derico.de;
    listen xxx.xx.xx.xxx:80;
    listen xxx.xx.xx.xxx:443 ssl;
    ssl_certificate /etc/ssl/derico.de.pem;
    ssl_certificate_key /etc/ssl/derico.de.key;
    if ( $host != $server_name ) {
        return 301 $scheme://$server_name$request_uri;

    }
    if ( $scheme != "https") {
        rewrite ^ https://$host$uri permanent;

    }
    proxy_read_timeout 300;
    location / {
        proxy_pass http://127.0.0.1:8080/VirtualHostBase/https/$server_name:443/Plone/VirtualHostRoot/$request_uri;

    }
}
By @MrTango in
Tags :