Setting up NginX
Version 1.4 by kuchumovn on 2009/12/19
I'm running XWiki Enterprise on Glassfish 2 Application Server.
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".
Glassfish is installed in /user/local/glassfish/glassfish folder.
I've configured my NginX as follows (/etc/nginx.conf):
user www-data;
worker_processes 1;
events {
worker_connections 1024;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
server {
listen 80;
server_name vostrets.ru;
# redirect all http://vostrets.ru/* requests to http://www.vostrets.ru/*
rewrite ^(.*) http://www.vostrets.ru$1 permanent;
}
server {
listen 80;
server_name www.vostrets.ru;
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/(.*)\.(jpg|jpeg|gif|png|ico) http://www.vostrets.ru/xwiki/$1.$2 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;
}
# ... bla bla bla ...
# forward all http://vostrets.ru/xwiki/ requests to http://vostrets.ru:8080/xwiki/
location /xwiki/ {
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;
expires 0m;
}
}
}
worker_processes 1;
events {
worker_connections 1024;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
server {
listen 80;
server_name vostrets.ru;
# redirect all http://vostrets.ru/* requests to http://www.vostrets.ru/*
rewrite ^(.*) http://www.vostrets.ru$1 permanent;
}
server {
listen 80;
server_name www.vostrets.ru;
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/(.*)\.(jpg|jpeg|gif|png|ico) http://www.vostrets.ru/xwiki/$1.$2 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;
}
# ... bla bla bla ...
# forward all http://vostrets.ru/xwiki/ requests to http://vostrets.ru:8080/xwiki/
location /xwiki/ {
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;
expires 0m;
}
}
}