Nginx

De MochilaWiki
Revisão de 19h20min de 20 de janeiro de 2011 por Banto Palmarino (discussão | contribs)
Ir para navegaçãoIr para pesquisar

-> nginx (compilado) + spawn-fcgi (php-fastcgi)

apt-get install libpcre3-dev libssl-dev build-essential php5-cgi
cd /usr/src
wget -c http://nginx.org/download/nginx-0.8.54.tar.gz
tar zxvf nginx-0.8.54.tar.gz
cd nginx-0.8.54/
wget http://download.snake.de/dist/ngx-fancyindex-0.3.tar.gz
tar zxvf ngx-fancyindex-0.3.tar.gz
./configure --prefix=/usr/local/nginx --user=www-data --group=www-data \
--without-mail_pop3_module --without-mail_imap_module --with-sha1=/usr/lib \
--without-mail_smtp_module --with-http_stub_status_module \
--with-http_ssl_module --http-log-path=/var/log/nginx/access.log \
--conf-path=/etc/nginx/nginx.conf  --pid-path=/var/run/nginx.pid \
--add-module=ngx-fancyindex-0.3
make
make install
cd /usr/src
wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar -xf spawn*
cd spawn*
./configure
make
cp src/spawn-fcgi /usr/bin/spawn-fcgi
wget http://pub.nkosi.org/nginx/iredmail/nginx-init
wget http://pub.nkosi.org/nginx/iredmail/php-fastcgi-bin
wget http://pub.nkosi.org/nginx/iredmail/php-fastcgi-init
wget http://pub.nkosi.org/iredmail/nginx-logrotate
wget http://pub.nkosi.org/iredmail/nginx.conf
mkdir /etc/nginx/sites-enabled
mv nginx.conf /etc/nginx/
mv nginx-init /etc/init.d/nginx
mv php-fastcgi-bin /usr/bin/php-fastcgi
mv php-fastcgi-init /etc/init.d/php-fastcgi
mv nginx-logrotate /etc/logrotate.d/nginx
echo cgi.fix_pathinfo = 1 >> /etc/php5/cgi/php.ini
chmod 755 /etc/init.d/nginx
chmod a+x /usr/bin/php-fastcgi
chmod 755 /etc/init.d/php-fastcgi
update-rc.d php-fastcgi defaults
update-rc.d nginx defaults

iniciando serviços

/etc/init.d/php-fastcgi start
/etc/init.d/nginx start

parando serviços

/etc/init.d/php-fastcgi stop
/etc/init.d/nginx stop

sintaxe para nginx.conf

em nginx.conf:

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

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

    access_log  /var/log/nginx/access.log;
    sendfile        on;
    keepalive_timeout  65;
    tcp_nodelay        on;
    gzip  on;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_min_length  1100;
    gzip_buffers 16 8k;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/gif image/jpeg image/png;
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    gzip_vary on;

    include /etc/nginx/sites-enabled/*;
}

vhost simples - em /etc/nginx/sites-enabled/pub.nkosi.net

    server {
        listen          80;
        server_name pub.nkosi.net;

        location / {
                root   /var/www/quijaua.com.br/pub/;
                index  index.html;
        }
  }

acrescentando log

access_log   /var/log/nginx/quijaua.com.br/pub/access.log;
error_log  /var/log/nginx/quijaua.com.br/pub/error.log info;

e para cada domínio cria o respectivo diretório

mkdir -p /var/log/nginx/quijaua.com.br/pub/

Desativa visualização de .htaccess & .htpassword

location ~ /\.ht {
   deny  all;
}

rodando php

        location / {
            root   /usr/share/apache2/;
            index  index.php index.html;
        }

         location ~ \.php$ {
            root            /usr/share/apache2/;
            include         fastcgi_params;
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME /usr/share/apache2$fastcgi_script_name;
            fastcgi_param SERVER_NAME $http_host;
            fastcgi_ignore_client_abort on;
        }

redirecionamento

        location / {
                rewrite ^ https://mail.elegbara.net/webmail permanent;
        }

listando itens de um diretório - simples

location  /  {
  root   /var/www/pub/;
  autoindex  on;
  autoindex_exact_size on
}

listando itens de um diretório - fancyindex

location  /  {
  root   /var/www/pub/;
  fancyindex on;
  fancyindex_exact_size off;
}

rodando perl/cgi

        location ~ ^/cgi-bin/.*\.pl$ {
                gzip off;
                fastcgi_pass  127.0.0.1:9000;
                include fastcgi_params;
                fastcgi_index cgi-bin.php;
                fastcgi_param SCRIPT_FILENAME /usr/share/apache2/cgi-bin.php;
                fastcgi_param SCRIPT_NAME /cgi-bin/cgi-bin.php;
                fastcgi_param X_SCRIPT_FILENAME /usr/lib$fastcgi_script_name;
                fastcgi_param X_SCRIPT_NAME $fastcgi_script_name;
        }

Para deixar publico a pasta /usr/share/doc

        location /doc {
                root   /usr/share;
        }

Ou um arquivo no caminho /srv/hatchepsut/nginx-powered.png

        location = /nginx-powered.png {
                root   /srv/hatchepsut;
                access_log   off;
        }

Alias

	location ^~ /phppgadmin {
        	alias /usr/share/phppgadmin/;
	}

Reescrita

        location /old_stuff/ {
            rewrite   ^/old_stuff/(.*)$  /new_stuff/$1  permanent;
        }

entrada para log

  log_format   main '$remote_addr - $remote_user [$time_local]  $status '
    '"$request" $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
                #permite o acesso para o ip         
                allow 127.0.0.1;

                #nega o acesso para todos
                deny all;

                #permite listar conteúdo da pasta
                autoindex on;

                #codificação da página
		charset utf-8; 
		charset         on;

                #não gera log
		access_log   off;

                #expira em 30 dias
		expires      30d;

                #restrição por senha - htpasswd
		auth_basic            "Restricted";
		auth_basic_user_file  /etc/awstats/webstats.example.com.htpasswd;