Wiki source code of Setting up NginX
Last modified by Eleni Cojocariu on 2026/04/23 13:53
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
![]() |
5.2 | 1 | {{box cssClass="floatinginfobox" title="**Contents**"}} |
| 2 | {{toc/}} | ||
| 3 | {{/box}} | ||
| 4 | |||
![]() |
9.2 | 5 | {{warning}} |
![]() |
9.4 | 6 | WIP: documentation page converted at [[Set up NginX Proxy Server>>documentation.xs.admin.installation.http-reverse-proxy.nginx-key-configurations.set-nginx.WebHome]]. |
![]() |
9.2 | 7 | {{/warning}} |
| 8 | |||
![]() |
5.2 | 9 | = Set up = |
| 10 | |||
![]() |
2.5 | 11 | {{warning}} |
![]() |
5.1 | 12 | * This configuration has been contributed by an XWiki user and needs to be verified. |
![]() |
2.5 | 13 | {{/warning}} |
| |
1.1 | 14 | |
![]() |
5.1 | 15 | Example running XWiki on the Glassfish 2 Application Server: |
![]() |
6.1 | 16 | |
![]() |
5.1 | 17 | * NginX listens on ##<domain>:80## and redirects HTTP queries to ##<domain>:8080## and thus NginX is referred to as "frontend" and Glassfish as "backend". |
| 18 | * Glassfish is installed in the ##/user/local/glassfish/glassfish## folder. | ||
| 19 | |||
![]() |
2.5 | 20 | For more information you can consult the [[NginX manual>>http://wiki.nginx.org/Main]]. |
| |
1.1 | 21 | |
![]() |
5.1 | 22 | NginX configuration example with ##<domain>## being ##vostrets.ru## (##/etc/nginx.conf##): |
| |
1.1 | 23 | |
| 24 | {{code}} | ||
| 25 | user www-data; | ||
| |
3.1 | 26 | worker_processes 2; # This should be equal to number of CPUs |
| |
1.1 | 27 | |
| |
3.1 | 28 | worker_rlimit_nofile 20000; # Max open file descriptors, increase if nginx is serving large amount of static data for many users |
| 29 | |||
| |
2.2 | 30 | events |
| 31 | { | ||
| |
3.1 | 32 | worker_connections 1024; # number of max connections per worker (worker_connections * worker_processes = max connections) |
| |
1.1 | 33 | use epoll; |
| |
3.1 | 34 | multi_accept on; |
| |
1.1 | 35 | } |
| 36 | |||
| |
3.1 | 37 | |
| |
2.2 | 38 | http |
| 39 | { | ||
| |
1.1 | 40 | include mime.types; |
| 41 | default_type application/octet-stream; | ||
| 42 | |||
| |
3.1 | 43 | server_tokens off; # don't send nginx version to end users |
| 44 | |||
| |
1.1 | 45 | sendfile on; |
| 46 | tcp_nopush on; | ||
| 47 | tcp_nodelay on; | ||
| 48 | |||
| |
3.1 | 49 | gzip on; |
| 50 | gzip_comp_level 4; # increase for better compression (values 1 to 9, 1 = fastest, 9 = slowest/best compression) | ||
| 51 | gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; # compress multiple mime types | ||
| 52 | gzip_vary on; # send Vary: Accept-Encoding header | ||
| 53 | gzip_proxied any; # enable compression for proxied requests | ||
| 54 | |||
| |
2.2 | 55 | server |
| 56 | { | ||
![]() |
9.2 | 57 | listen 80; |
| |
1.1 | 58 | |
| 59 | server_name vostrets.ru; | ||
| 60 | |||
| 61 | # redirect all http://vostrets.ru/* requests to http://www.vostrets.ru/* | ||
| 62 | rewrite ^(.*) http://www.vostrets.ru$1 permanent; | ||
| 63 | } | ||
| 64 | |||
| |
2.2 | 65 | server |
| 66 | { | ||
| |
1.1 | 67 | listen 80; |
| 68 | |||
| 69 | server_name www.vostrets.ru; | ||
| 70 | |||
| 71 | charset utf-8; | ||
| 72 | |||
| 73 | access_log /var/log/nginx_access.log; | ||
| 74 | |||
| 75 | # count skin images for static data, though they are in "bin" path | ||
| |
2.2 | 76 | location ~* ^/xwiki/bin/skin/(.*)\.(jpg|jpeg|gif|png|ico)$ |
![]() |
9.2 | 77 | { |
| |
1.4 | 78 | access_log off; |
| 79 | |||
| |
2.2 | 80 | rewrite ^/xwiki/bin/skin/(.*) /xwiki/$1 permanent; |
| |
1.4 | 81 | |
| |
2.1 | 82 | expires max; |
| 83 | } | ||
| 84 | |||
| |
1.1 | 85 | # fetch all the data, which doesn't lie in "bin" path, as static data |
| |
2.2 | 86 | location ~* ^/xwiki(?!/bin/).+\.(jpg|jpeg|gif|png|ico|css|js)$ |
![]() |
9.2 | 87 | { |
| |
1.1 | 88 | access_log off; |
| |
1.3 | 89 | |
| 90 | # ${root} is the path, where the static files lie (i.e. ${root}/xwiki/skins/toucan/logo.png) | ||
| |
1.1 | 91 | root /user/local/glassfish/glassfish/domains/default_domain/applications/j2ee-modules; |
| |
2.2 | 92 | |
| |
1.1 | 93 | expires max; |
| 94 | } | ||
| 95 | |||
| |
2.3 | 96 | # forward all http://vostrets.ru/ requests to http://vostrets.ru:8080/ |
| 97 | location / | ||
![]() |
9.2 | 98 | { |
| |
1.1 | 99 | proxy_pass http://localhost:8080; |
| 100 | proxy_set_header X-Real-IP $remote_addr; | ||
| 101 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 102 | proxy_set_header Host $http_host; | ||
| |
4.1 | 103 | proxy_set_header X-Forwarded-Proto $scheme; |
| |
1.1 | 104 | |
| |
2.3 | 105 | expires 0m; |
| |
1.1 | 106 | } |
| |
2.2 | 107 | |
| 108 | # ... | ||
| |
1.1 | 109 | } |
| 110 | } | ||
| 111 | {{/code}} | ||
![]() |
5.1 | 112 | |
| 113 | = Troubleshooting = | ||
| 114 | |||
| 115 | == Request Entity Too Large == | ||
| 116 | |||
| 117 | If you find the following message in your logs: {{code}}Failed to load resource: the server responded with a status of 413 (Request Entity Too Large){{/code}} then you might want to try to [[increase the request body size>>http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size]] since it seems nginx does not allow request bodies larger than 1MB by default. |


