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