Replacing apache with nginx

Stephen Nelson-Smith sanelson at
Tue Sep 30 22:13:53 MSD 2008

I have apache 2.2 load-balancing a pool of 3 tomcat servers.  I want
to replace it with nginx.  I have the following very simple setup to
test the concept:

user  nginx;
worker_processes  2;

error_log  logs/error.log debug;

pid        logs/;

events {
    worker_connections  1024;

http {
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] $status '
                      '"$request" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay    on;

    server {
        listen       80;
        server_name  www.mysite.dmz;
        large_client_header_buffers 4 16k;

        access_log  logs/host.access.log  main;

        # Main location
        location / {
            proxy_redirect     off;

            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

            client_max_body_size       10m;
            client_body_buffer_size    128k;

            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;

            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;


This seems to work ok, although I've not yet looked up what each thing
does.  What I need it to do, which I had some problems doing with
apache is the following:

1) Needs to loadbalance over 3 servers
2) Sessions need to be sticky - so the user goes to the same server
all the time, after the session is started.
3) All http traffic needs to be coerced to https apart from

Any pointers to example configs or bits of the documentation would be
most welcome.  I'm just diving into the wiki now, but and handy
pointers would be a great help.



More information about the nginx mailing list