Wiki source code of Setting up NginX
Version 3.1 by Lukas Raska on 2014/03/27
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{warning}} | ||
2 | * This configuration is highly experimental and using it may be risky | ||
3 | * You likely won't need NginX if you have just a couple of hundred users browsing your wiki | ||
4 | {{/warning}} | ||
5 | |||
6 | I'm running XWiki Enterprise on the Glassfish 2 Application Server. | ||
7 | NginX listens on //vostrets.ru:80// and redirects HTTP queries to //vostrets.ru:8080// and thus NginX is referred to as "frontend" and Glassfish as "backend". | ||
8 | Glassfish is installed in the ///user/local/glassfish/glassfish// folder. | ||
9 | |||
10 | For more information you can consult the [[NginX manual>>http://wiki.nginx.org/Main]]. | ||
11 | |||
12 | I've configured my NginX as follows (**///etc/nginx.conf//**): | ||
13 | |||
14 | {{code}} | ||
15 | user www-data; | ||
16 | worker_processes 2; # This should be equal to number of CPUs | ||
17 | |||
18 | worker_rlimit_nofile 20000; # Max open file descriptors, increase if nginx is serving large amount of static data for many users | ||
19 | |||
20 | events | ||
21 | { | ||
22 | worker_connections 1024; # number of max connections per worker (worker_connections * worker_processes = max connections) | ||
23 | use epoll; | ||
24 | multi_accept on; | ||
25 | } | ||
26 | |||
27 | |||
28 | http | ||
29 | { | ||
30 | include mime.types; | ||
31 | default_type application/octet-stream; | ||
32 | |||
33 | server_tokens off; # don't send nginx version to end users | ||
34 | |||
35 | sendfile on; | ||
36 | tcp_nopush on; | ||
37 | tcp_nodelay on; | ||
38 | |||
39 | gzip on; | ||
40 | gzip_comp_level 4; # increase for better compression (values 1 to 9, 1 = fastest, 9 = slowest/best compression) | ||
41 | gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; # compress multiple mime types | ||
42 | gzip_disable "msie6"; # disable gzip for IE<=6 | ||
43 | gzip_vary on; # send Vary: Accept-Encoding header | ||
44 | gzip_proxied any; # enable compression for proxied requests | ||
45 | |||
46 | server | ||
47 | { | ||
48 | listen 80; | ||
49 | |||
50 | server_name vostrets.ru; | ||
51 | |||
52 | # redirect all http://vostrets.ru/* requests to http://www.vostrets.ru/* | ||
53 | rewrite ^(.*) http://www.vostrets.ru$1 permanent; | ||
54 | } | ||
55 | |||
56 | server | ||
57 | { | ||
58 | listen 80; | ||
59 | |||
60 | server_name www.vostrets.ru; | ||
61 | |||
62 | charset utf-8; | ||
63 | |||
64 | access_log /var/log/nginx_access.log; | ||
65 | |||
66 | # count skin images for static data, though they are in "bin" path | ||
67 | location ~* ^/xwiki/bin/skin/(.*)\.(jpg|jpeg|gif|png|ico)$ | ||
68 | { | ||
69 | access_log off; | ||
70 | |||
71 | rewrite ^/xwiki/bin/skin/(.*) /xwiki/$1 permanent; | ||
72 | |||
73 | expires max; | ||
74 | } | ||
75 | |||
76 | # fetch all the data, which doesn't lie in "bin" path, as static data | ||
77 | location ~* ^/xwiki(?!/bin/).+\.(jpg|jpeg|gif|png|ico|css|js)$ | ||
78 | { | ||
79 | access_log off; | ||
80 | |||
81 | # ${root} is the path, where the static files lie (i.e. ${root}/xwiki/skins/toucan/logo.png) | ||
82 | root /user/local/glassfish/glassfish/domains/default_domain/applications/j2ee-modules; | ||
83 | |||
84 | expires max; | ||
85 | } | ||
86 | |||
87 | # forward all http://vostrets.ru/ requests to http://vostrets.ru:8080/ | ||
88 | location / | ||
89 | { | ||
90 | proxy_pass http://localhost:8080; | ||
91 | proxy_set_header X-Real-IP $remote_addr; | ||
92 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
93 | proxy_set_header Host $http_host; | ||
94 | |||
95 | expires 0m; | ||
96 | } | ||
97 | |||
98 | # ... | ||
99 | } | ||
100 | } | ||
101 | {{/code}} |