Nginx

From campisano.org
Jump to navigation Jump to search

Vademecum

Environment

# cat /etc/debian_version 
6.0.4
# gcc -v
gcc version 4.4.5
Debian 4.4.5-8
# uname -r
3.1.0-1-amd64


Nginx

apt-get install libssl-dev libpcre3-dev
mkdir /srv/local/nginx
chown nobody:nogroup /srv/local/nginx
su -s /bin/bash nobody
wget http://nginx.org/download/nginx-1.0.12.tar.gz
tar -xzf nginx-1.0.12.tar.gz
cd nginx-1.0.12
./configure --prefix=/srv/local/nginx --with-http_ssl_module
make
make install
exit
chown www-data:www-data /srv/local/nginx/logs/

Php-cgi support

apt-get install php5-cli php5-cgi php5-odbc php5-mysql php5-pgsql php5-sqlite php5-mcrypt php-xml-parser php-mail php5-imap

Init script


Config file

Start unprivileged nginx daemon with 'su www-data -c "${PREFIX}bin/nginx"' on port 8080, see Nginx init script


worker_processes 1;

events {
    worker_connections 512;
}

http {
    include      mime.types;
    default_type application/octet-stream;

    keepalive_timeout 30;

    gzip on;

    server {
        listen      8080;
        server_name NOMEHOST.org;
        rewrite     ^ $scheme://www.NOMEHOST.org$uri? permanent;
    }

    server {
        listen      8080;
        server_name www.NOMEHOST.org;
        root        /srv/domain/NOMEHOST.org/www;
        access_log  /srv/domain/NOMEHOST.org/log/access.log;
        error_log   /srv/domain/NOMEHOST.org/log/error.log;

        index   index.html index.php;

        location = /robots.txt  { access_log off; log_not_found off; }
        location = /favicon.ico { access_log off; log_not_found off; }	

        # this prevents hidden files (beginning with a period) from being served
        location ~ /\.          { access_log off; log_not_found off; deny all; }
        location ~ ~$           { access_log off; log_not_found off; deny all; }

        location ~* \.(jpg|jpeg|gif|css|png|js|ico|swf)$ {
            access_log off;
            expires 1h;
        }

        location ~ \.php$ {
            include        fastcgi_params;
            fastcgi_pass   unix:/tmp/php-cgi.socket;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
}


References