apt-get install nginx-extras
#################################
# Centrala Baza Danych Autosanu #
# cbda.autosan.pl proxy ssl #
# for IBM websphere server #
#################################upstream cbda_proxy_ssl {
server 172.16.4.56:80;
}
server {
listen 82.177.196.204:80;
server_name cbda.autosan.pl;
return 301 https://$server_name$request_uri;
access_log /var/log/nginx/access.cbda.autosan.pl.log;
error_log /var/log/nginx/error.cbda.autosan.pl.log;
more_clear_headers "Content-Type: ";
more_clear_headers "Accept-Ranges: ";
more_clear_headers "Content-Length: ";}server {
listen 82.177.196.204:443 ssl;
server_name cbda.autosan.pl;
access_log /var/log/nginx/access.cbda.autosan.pl-ssl.log;
error_log /var/log/nginx/error.cbda.autosan.pl-ssl.log;
more_clear_headers "Content-Type: ";
more_clear_headers "Accept-Ranges: ";
more_clear_headers "Content-Length: "; ssl on;
ssl_certificate /etc/ssl/certs/cbda.autosan.pl.cert;
ssl_certificate_key /etc/ssl/private/cbda.autosan.pl.key;
ssl_trusted_certificate /etc/ssl/certs/autosan.pl-cacert.crt; ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m; ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS; add_header Strict-Transport-Security "max-age=31536000"; location / {
if ($remote_addr ~ "^(82.177.196.192/27)$")
{ proxy_pass http://cbda_proxy_ssl; }
rewrite ^/ https://cbda.autosan.pl/service/service;
} location ~^(/service|/resources|/images|/primefaces_resource) {
proxy_pass http://cbda_proxy_ssl;
error_page 404 = /404.html; #proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
}
location @badip {
return 301 $scheme://example.com/some-page;
} error_page 500 502 503 504 /50x.html;}Load Balancing - Rozkład ruchu na kilka serwerów
Używamy modułu upstream by zdefiniować kilka serwerów serwujących naszą stronę. Następnie dla bloku "serwer" przekazujemy połączenia tym serwerom za pomocą
proxy_pass http://NAZWA_LISTY_UPSTREAMhttp {
upstream myproject {
server 127.0.0.1:8000 weight=3;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
} server {
listen: 80;
server_name: www.domain.com;
location / {
proxy_pass http://myproject;
}
}
}
Serwer dla statycznych plików Oto pełna konfiguracja dla prostego serwera serwującego statyczną treść:
user www-data www-data; worker_processes 2;
server
SynopsisThis module adds the HTTP and WebDAV methods PUT, DELETE, MKCOL, COPY and MOVE.This module is not compiled by default. It is necessary to enable it at compile-time via./configure --with-http_dav_moduleExample:location / {
root /data/www;
client_body_temp_path /data/client_temp; dav_methods PUT DELETE MKCOL COPY MOVE; create_full_put_path on;
dav_access group:rw all:r; limit_except GET {
allow 192.168.1.0/32;
deny all;
}
}Edit section: Directives Directives
Edit section: dav access dav_accesssyntax: dav_access user:permissions [users:permissions] ...default: dav_access user:rwcontext: http, server, locationThis directive assigns access rights for file and directories, for example:dav_access user:rw group:rw all:r;If assigning any permissions for groups or all, then it's not necessary to indicate permissions for user:dav_access group:rw all:r;Edit section: dav methods dav_methodssyntax: dav_methods [off|put|delete|mkcol|copy|move] ...default: dav_methods offcontext: http, server, locationThis directive enables specified HTTP and WebDAV methods. Setting it to off disables all methods, ignoring the remaining parameters.For the PUT method the destination file must reside on the same partition as the directory where the temporary file is stored (given by directive client_body_temp_path in the location section).When a file is created using the PUT method it is possible to assign the modification date by setting the Date header.
Edit section: create full put path create_full_put_pathsyntax: create_full_put_path on|offdefault: create_full_put_path offcontext: http, server, locationBy default, the PUT method can only create files within existing directories. This directive permits creating all necessary intermediate directories.
Gdy używamy haproxy (czy jakiegokolwiek innego proxy) pojawia się mały problem, mianowicie backend widzi wszystkie połączenia jako pochodzące z IP maszyny. Jest to problemem przy logowaniu oraz dla niektórych aplikacji. Większość serwerów WWW ma moduł który pozwala na “odzyskanie” IPka z nagłówka “X-Forwarded-For”. Oczywiście Twoje proxy musi umieć przekazywać taki nagłówek ale większość robi to domyślnie albo potrafi po włączeniu odpowiednich opcji (np. haproxy: option forwardfor except 127.0.0.1)Tak na szybko:Lighttpd:server.modules = (
"mod_access",
"mod_alias",
"mod_accesslog",
"mod_extforward",
"mod_expire",
"mod_compress",
"mod_rewrite",
"mod_extforward",
)extforward.headers = ("X-Forwarded-For")
extforward.forwarder = ("127.0.0.1" => "trust")extforward musi być po mod_accesslog, inaczej logi nie będą widzieć tego “prawdziwego” IPka (tak wiem, dziwne)
Apache# aptitude install libapache2-mod-rpaf(w debianie uruchamia się automatycznie z konfigiem “ufającym” 127.0.0.1, jak Twoje proxy jest gdzie indziej zmień w /etc/apache2/mods-available/rpaf.conf)
Nginx set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;wymaga nginxa ze squeeze, w lennym jest trochę za stary aptitude install fcgiwrap
# smokeping
location /smokeping/ {
index smokeping.cgi;
gzip off;
if ($uri ~ "/smokeping/smokeping.cgi") {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
include fastcgi_params;
} ln -s /usr/share/smokeping/www /var/www/smokeping
ln -s /usr/share/smokeping/cgi-bin/smokeping.cgi /var/www/smokeping/
Using Nginx as a load balancer30 December 2009Here’s a look at how nginx does basic load balancing :upstream yoursite {
server yoursite1.yoursite.com;
server yoursite2.yoursite.com;
}server {
server_name www.yoursite.com;
location / {
proxy_pass http://yoursite;
}
}This configuration will send 50% of the requests for www.yoursite.com to yoursite1.yoursite.com and the other 50% to yoursite2.yoursite.com.
ip_hashYou can specify the ip_hash directive that guarantees the client request will always be transferred to the same server.
If this server is considered inoperative, then the request of this client will be transferred to another server.upstream yoursite {
ip_hash;
server yoursite1.yoursite.com;
server yoursite2.yoursite.com;
}downIf one of the servers must be removed for some time, you must mark that server as down.upstream yoursite {
ip_hash;
server yoursite1.yoursite.com down;
server yoursite2.yoursite.com;
}weightIf you add a weight tag onto the end of the server definition you can modify the percentages of the requests send to the servers.
When there’s no weight set, the weight is equal to one.upstream yoursite {
server yoursite1.yoursite.com weight=4;
server yoursite2.yoursite.com;
}This configuration will send 80% of the requests to yoursite1.yoursite.com and the other 20% to yoursite2.yoursite.com.note: It’s not possible to combine ip_hash and weight directives.
max_fails and fail_timeoutmax_fails is a directive defining the number of unsuccessful attempts in the
time period defined by fail_timeout before the server is considered inoperative.
If not set, the number of attempts is one. A value of 0 turns off this check.
If fail_timeout is not set the time is 10 seconds.upstream yoursite {
server yoursite1.yoursite.com;
server yoursite2.yoursite.com max_fails=3 fail_timeout=30s;
}In this configuration nginx will consider yoursite2.yoursite.com as inoperative
if a request fails 3 times with a 30s timeout.
backupIf the non-backup servers are all down or busy, the server(s) with the backup directive will be used.upstream yoursite {
server yoursite1.yoursite.com max_fails=3;
server yoursite2.yoursite.com max_fails=3;
server yoursite3.yoursite.com backup;
}This configuration will send 50% of the requests for www.yoursite.com to yoursite1.yoursite.com and the other 50% to yoursite2.yoursite.com.
If yoursite1.yoursite.com and yoursite2.yoursite.com both fails 3 times the requests will be send to yoursite3.yoursite.com.http://wiki.nginx.org/HttpUpstreamModule