Hetzner - DokuWiki

Nginx, PHP5, FCGI, XCache

Informationen, Quellen, Wiki: http://wiki.nginx.org/Main

Wer Russisch kann: http://nginx.org/ru/

Inhaltsverzeichnis

Benutzer und Gruppe anlegen, unter dem Nginx laufen soll

groupadd nginx
useradd -g nginx nginx

Kompilieren der Nginx Quellen

Hinweise zu Optionen und Modulen gibt es hier und hier

/configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
make -j3
sudo make install

Nginx Konfiguration (/usr/local/nginx/conf/nginx.conf)

# Benutzer unter dem Nginx läuft.
user nginx nginx;

# Anzahl der Server-Instanzen. Zwei ist ein guter Wert bei Dual Core CPUs.
worker_processes 2;

# Zum einlesen einer geänderten Konfiguration: kill -HUP `cat /var/log/nginx.pid`
pid logs/nginx.pid;

events {
  use epoll;
  # max_clients = worker_processes * worker_connections,
  # while in reverse proxy mode: max_clients = worker_processes * worker_connections/4
  worker_connections  1024;
}

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

  error_log	/usr/local/nginx/logs/nginx_error.log error;

  sendfile        on;
  tcp_nopush  on;
  tcp_nodelay off;
  keepalive_timeout  60;

  # Kompression
  gzip on;
  gzip_comp_level 1;
  gzip_proxied any;
  gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml
              application/xml+rss text/javascript;

  server {
    listen		SRV_IP:SRV_PORT;
    server_name 	DOMAIN.TLD *.DOMAIN.TLD;

    # Pfad zum Document Root
    root 		/bla/blubb/www/public_html/;

    access_log      /bla/blubb/www/log/nginx_access.log;

    location / {
      index index.html
    }

    #error_page  404              /404.html;
    #error_page   500 502 503 504  /50x.html;
    #location = /50x.html {
    #    root   html;
    #}

    # PHP Anfragen an FastCGI Backend

    location ~ \.php$ {
     # Generelle FCGI Einstellungen werden geladen
     include conf/fastcgi_params;
     # FCGI Server lauscht auf localhost, port 9000
     # Unix Socket wäre auch möglich (unix:/path/file.sock)
     fastcgi_pass  127.0.0.1:9000;
     fastcgi_index index.php;
     # PHP Datei (DocRooot + URI (Variable $fastcgi_script_name) wird an FCGI Server übergeben.
     fastcgi_param  SCRIPT_FILENAME  /bla/blubb/www/public_html$fastcgi_script_name;
    }

  }

}

Skript zum Starten der FastCGI Backends

#!/bin/sh

## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/home/soellner/www/bin/spawn-fcgi"

## ABSOLUTE path to the PHP binary
FCGIPROGRAM="/home/soellner/www/bin/php-fcgi"

## bind to tcp-port on localhost
## FCGISOCKET="/path/file.sock"

## bin to ip address and port
FCGIIP=127.0.0.1
FCGIPORT=9000

## uncomment the PHPRC line, if you want to have an extra php.ini for this user
## store your custom php.ini in /var/www/fastcgi/fred/php.ini
## with an custom php.ini you can improve your security
## just set the open_basedir to the users webfolder
## Example: (add this line in you custom php.ini)
## open_basedir = /var/www/vhosts/fred/html
##
PHPRC="/Pfad/zu/php.ini"

## number of PHP childs to spawn in addition to the default. Minimum of 2.
## Actual childs = PHP_FCGI_CHILDREN + 1
PHP_FCGI_CHILDREN=4

## number of request server by a single php-process until is will be restarted
PHP_FCGI_MAX_REQUESTS=1000

## IP adresses where PHP should access server connections from
FCGI_WEB_SERVER_ADDRS="127.0.0.1"

# allowed environment variables sperated by spaces
ALLOWED_ENV="PATH USER"

## if this script is run as root switch to the following user
USERID=name
GROUPID=group

################## no config below this line

if test x$PHP_FCGI_CHILDREN = x; then
 PHP_FCGI_CHILDREN=5
fi

export PHP_FCGI_MAX_REQUESTS
export FCGI_WEB_SERVER_ADDRS
export PHPRC

ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS PHPRC"

# copy the allowed environment variables
E=

for i in $ALLOWED_ENV; do
  E="$E $i=$(eval echo "\$$i")"
done

# clean environment and set up a new one
env - $E $SPAWNFCGI -a $FCGIIP -p $FCGIPORT -f $FCGIPROGRAM -u $USERID -g $GROUPID -C $PHP_FCGI_CHILDREN

In Bearbeitung --Seldon 11:28, 5. Dez 2007 (CET)



© 2018. Hetzner Online GmbH. Alle Rechte vorbehalten.