Setting up NginX

Last modified by Vincent Massol on 2017/09/06

Set up

  • This configuration has been contributed by an XWiki user and needs to be verified.
  • You likely won't need NginX if you have just a couple of hundred users browsing your wiki

Example running XWiki on the Glassfish 2 Application Server:

  • NginX listens on <domain>:80 and redirects HTTP queries to <domain>:8080 and thus NginX is referred to as "frontend" and Glassfish as "backend".
  • Glassfish is installed in the /user/local/glassfish/glassfish folder.

For more information you can consult the NginX manual.

NginX configuration example with <domain> being (/etc/nginx.conf):

user www-data;
worker_processes  2; # This should be equal to number of CPUs

worker_rlimit_nofile 20000; # Max open file descriptors, increase if nginx is serving large amount of static data for many users

    worker_connections  1024; # number of max connections per worker (worker_connections * worker_processes = max connections)
    use epoll;
    multi_accept on;

    include       mime.types;
    default_type  application/octet-stream;

    server_tokens off; # don't send nginx version to end users

    sendfile       on;
    tcp_nopush     on;
    tcp_nodelay    on;

    gzip            on;
    gzip_comp_level 4; # increase for better compression (values 1 to 9, 1 = fastest, 9 = slowest/best compression)
    gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; # compress multiple mime types
    gzip_disable    "msie6"; # disable gzip for IE<=6
    gzip_vary       on; # send Vary: Accept-Encoding header
    gzip_proxied    any; # enable compression for proxied requests

listen 80;


        # redirect all* requests to*
        rewrite ^(.*)$1 permanent;

        listen 80;

        charset utf-8;

        access_log  /var/log/nginx_access.log;

        # count skin images for static data, though they are in "bin" path
        location ~* ^/xwiki/bin/skin/(.*)\.(jpg|jpeg|gif|png|ico)$
            access_log off;

            rewrite ^/xwiki/bin/skin/(.*) /xwiki/$1 permanent;

            expires max;

        # fetch all the data, which doesn't lie in "bin" path, as static data
        location ~* ^/xwiki(?!/bin/).+\.(jpg|jpeg|gif|png|ico|css|js)$
            access_log off;

            # ${root} is the path, where the static files lie (i.e. ${root}/xwiki/skins/toucan/logo.png)
            root /user/local/glassfish/glassfish/domains/default_domain/applications/j2ee-modules;

            expires max;

        # forward all requests to
        location /
            proxy_pass              http://localhost:8080;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header        Host $http_host;
            proxy_set_header        X-Forwarded-Proto $scheme;

            expires 0m;

        # ...


Request Entity Too Large

If you find the following message in your logs: Failed to load resource: the server responded with a status of 413 (Request Entity Too Large) then you might want to try to increase the request body size since it seems nginx does not allow request bodies larger than 1MB by default.

Created by Vincent Massol on 2017/09/06

Get Connected