tFF.msk.ru :: Sharing tFFed mind
Март 29, 2024, 13:56:29 *
Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.

Войти
Новости: Пропал ребенок. Вся информация и фотографии здесь.
 
   Начало   Помощь Поиск Войти Регистрация  
Страниц: [1]   Вниз
  Печать  
Автор Тема: nginx и другие "легкие" вебсерверы  (Прочитано 18617 раз)
0 Пользователей и 1 Гость смотрят эту тему.
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« : Сентябрь 19, 2007, 14:38:26 »

CHM-файл (WinHelp) помощи к nginx смотри в аттаче (по состоянию на сентябрь 2007)


скрипт для запуска PHP5-FastCGI из коммандной строки (localhost:9000)
Код:
#!/bin/bash

## ABSOLUTE path to the PHP binary
PHPFCGI="/usr/lib/cgi-bin/php5"

## tcp-port to bind on
FCGIPORT="9000"

## IP to bind on
FCGIADDR="127.0.0.1"

## number of PHP children to spawn
PHP_FCGI_CHILDREN=5

## number of request before php-process will be restarted
PHP_FCGI_MAX_REQUESTS=1000

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

## if this script is run as root switch to the following user
USERID=www-data

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

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

ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN"
ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS"
ALLOWED_ENV="$ALLOWED_ENV FCGI_WEB_SERVER_ADDRS"

if test x$UID = x0; then
  EX="/bin/su -m -c \"$PHPFCGI -q -b $FCGIADDR:$FCGIPORT\" $USERID"
else
  EX="$PHPFCGI -b $FCGIADDR:$FCGIPORT"
fi

echo $EX

# copy the allowed environment variables
E=

for i in $ALLOWED_ENV; do
  E="$E $i=${!i}"
done

# clean environment and set up a new one
nohup env - $E sh -c "$EX" &> /dev/null &


скрипт для автоматического запуска PHP5-FastCGI из init.d (initscript) взят отсюда (оригинал страницы в аттаче - читай комментарии):
ошибки исправлены (cами файлы - в аттаче, непосредственно скрипты. под Debian4 полет нормальный)

The init script:
/etc/init.d/php-fastcgi
Код:
#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-fastcgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop php-cgi in external FASTCGI mode
# Description:       Start and stop php-cgi in external FASTCGI mode
### END INIT INFO

# Author: Kurt Zankl <[EMAIL PROTECTED]>

# Do NOT "set -e"

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="php-cgi in external FASTCGI mode"
NAME=php-fastcgi
DAEMON=/usr/bin/php5-cgi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
PHP_CONFIG_FILE=/etc/php5/cgi/php.ini

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# If the daemon is not enabled, give the user a warning and then exit,
# unless we are stopping the daemon
if [ "$START" != "yes" -a "$1" != "stop" ]; then
        log_warning_msg "To enable $NAME, edit /etc/default/$NAME and set START=yes"
        exit 0
fi

# Process configuration
export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
DAEMON_ARGS="-q -b $FCGI_HOST:$FCGI_PORT -c $PHP_CONFIG_FILE"

do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
                || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
                --background --make-pidfile --chuid $EXEC_AS_USER --startas $DAEMON -- \
                $DAEMON_ARGS \
                || return 2
}

do_stop()
{
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE > /dev/null # -name $DAEMON
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        # Wait for children to finish too if this is a daemon that forks
        # and if the daemon is only ever run from this initscript.
        # If the above conditions are not satisfied then add some other code
        # that waits for the process to drop all resources that could be
        # needed by services started subsequently.  A last resort is to
        # sleep for some time.
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
        [ "$?" = 2 ] && return 2
        # Many daemons don't delete their pidfiles when they exit.
        rm -f $PIDFILE
        return "$RETVAL"
}
case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  restart|force-reload)
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
        exit 3
        ;;
esac

Установка:
Цитировать
Tweak the init script a little, put it in /etc/init.d/php-fastcgi, sudo chmod +x /etc/init.d/php-fastcgi, run sudo update-rc.d php-fastcgi defaults and place the configuration for the script in /etc/default/php-fastcgi

Config file for init script (the init script looks for this):
/etc/default/php-fastcgi
Код:
START=yes

# Which user runs PHP? (default: www-data)

EXEC_AS_USER=www-data

# Host and TCP port for FASTCGI-Listener (default: localhost:9000)

FCGI_HOST=localhost
FCGI_PORT=9000

# Environment variables, which are processed by PHP

PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000

nginx config file:
/etc/nginx/nginx.conf
Код:
location ~ \.php$ {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME  /var/www/blog.codefront.net$fastcgi_script_name;
  include        /etc/nginx/fastcgi.conf;
}

My fastcgi.conf file (I’m not sure I need everything here…)
Код:
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;


Taкже смотри:
http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg352883.html

там вот это:
Код:
Package: php5-cgi
Version: 5.2.0-8+etch1
Severity: minor
Tags: patch


There was no Init-script for php-cgi in external FASTCGI Mode (Daemon mode) included. So I adapted /etc/init.d/skeleton for this application.

Start before httpd, stop after httpd:
  # update-rc.d php-fastcgi defaults 19 21

Attached: /etc/init.d/php-fastcgi, /etc/default/php-fastcgi

PS: Tested with nginx httpd.

#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-fastcgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop php-cgi in external FASTCGI mode
# Description:       Start and stop php-cgi in external FASTCGI mode
### END INIT INFO

# Author: Kurt Zankl <[EMAIL PROTECTED]>

# Do NOT "set -e"

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="php-cgi in external FASTCGI mode"
NAME=php-fastcgi
DAEMON=/usr/bin/php-cgi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# If the daemon is not enabled, give the user a warning and then exit,
# unless we are stopping the daemon
if [ "$START" != "yes" -a "$1" != "stop" ]; then
        log_warning_msg "To enable $NAME, edit /etc/default/$NAME and set
START=yes"
        exit 0
fi

# Process configuration
export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
DAEMON_ARGS="-q -b $FCGI_HOST:$FCGI_PORT"


do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
--test > /dev/null \
                || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
                --background --make-pidfile --chuid $EXEC_AS_USER --startas
$DAEMON -- \
                $DAEMON_ARGS \
                || return 2
}

do_stop()
{
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile
$PIDFILE > /dev/null # --name $DAEMON
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        # Wait for children to finish too if this is a daemon that forks
        # and if the daemon is only ever run from this initscript.
        # If the above conditions are not satisfied then add some other code
        # that waits for the process to drop all resources that could be
        # needed by services started subsequently.  A last resort is to
        # sleep for some time.
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec
$DAEMON
        [ "$?" = 2 ] && return 2
        # Many daemons don't delete their pidfiles when they exit.
        rm -f $PIDFILE
        return "$RETVAL"
}

case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  restart|force-reload)
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
        exit 3
        ;;
esac

:


#
# Settings for php-cgi in external FASTCGI Mode
#

# Should php-fastcgi run automatically on startup? (default: no)

START=yes

# Which user runs PHP? (default: www-data)

EXEC_AS_USER=www-data

# Host and TCP port for FASTCGI-Listener (default: localhost:9000)

FCGI_HOST=localhost
FCGI_PORT=9000

# Environment variables, which are processed by PHP

PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000


* nginx-winhelp.rar (113.88 Кб - загружено 595 раз.)
* php_fcgi_initscript.pdf (39.61 Кб - загружено 985 раз.)
* php5_initscript.rar (3.06 Кб - загружено 599 раз.)
« Последнее редактирование: Сентябрь 30, 2007, 20:15:06 от tFF » Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #1 : Сентябрь 19, 2007, 18:03:03 »

nginx rewrite для Wordpress

было:
Код:
# BEGIN WordPress

RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

# END WordPress

стало:
Код:
location /blog/ {
      index index.php;
        if (-e $request_filename) {
          break;
        }
      rewrite ^/blog/(.+)$ /blog/index.php?q=$1 last;
    }

или:
Код:
location /blog/ {
      index index.php index.html;
      if (!-e $request_filename) {
        rewrite ^/blog/(.+)$ /blog/index.php?q=$1 last;
      }
}
Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #2 : Сентябрь 19, 2007, 20:48:47 »

/etc/apt/sources.list:

http://deb.wapper.ru/nginx/:
Код:
deb http://deb.wapper.ru/nginx/ ./
(здесь версия поновее, чем в том, который ниже)

http://packages.debian.org/unstable/web/nginx
(здесь версия остает. репозитарий выбрать из списка зеркал и заменить в строке примера, которая приведена на странице для венсения в sources.list)
« Последнее редактирование: Сентябрь 20, 2007, 21:03:18 от tFF » Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #3 : Сентябрь 20, 2007, 19:52:35 »

Быстрый, featurerich и нересурсоемкий http-сервер
http://www.lighttpd.net/
Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #4 : Сентябрь 20, 2007, 19:54:07 »

nginx vs lighttpd
Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #5 : Сентябрь 20, 2007, 19:56:17 »

любопытная статья по настройке серверов, обслуживающих большое кол-во соединений
The C10K problem
Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #6 : Сентябрь 20, 2007, 20:00:44 »

http://www.litespeedtech.com/
вроде бы он делает и nginx, и lighttpd
Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #7 : Октябрь 05, 2007, 18:15:51 »

Mathopd is a very small, yet very fast HTTP server for UN*X systems.
Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #8 : Май 26, 2008, 17:57:28 »

Для запуска CGI-скриптов можно поставить перл-обертку... Подробнее (или в аттаче):

* NginxSimpleCGI_rev10.rar (36.47 Кб - загружено 587 раз.)
« Последнее редактирование: Май 26, 2008, 20:10:03 от tFF » Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #9 : Июнь 09, 2009, 00:45:45 »

Если nginx выдает http-ошибку 400 для https-хоста, когда https настроен на нестандартном порту (не tcp:43), делаем следующее:

1. Сработало.
Код:
# Set this if u get "400 bad request error. The plain HTTP request was sent to HTTPS port"
error_page  497      https://example.com:8080$request_uri;

2. Не сработало, но, говорят, помогает в случае проблем с phpmyadmin'ом.
Код:
        location ~ \.php$ {
    # Set to "on" if u get "400 bad request error. The plain HTTP request was sent to HTTPS port"
    fastcgi_param  HTTPS on;

...
}
Записан

So it goes...
tFF
Administrator
Sr. Member
*****
Offline Offline

Сообщений: 422



WWW
« Ответ #10 : Июнь 23, 2011, 01:43:55 »

http://nginx.org/pipermail/nginx/2007-February/000703.html

http://forum.nginx.org/read.php?2,29271,29572
Цитировать
> Where do you use that directive. Under the HTTP block its giving me no
> errors

It's allowed in http, server, if in server, location, if in location
contexts.

With the following config

error_log /path/to/error_log notice;
rewrite_log on;

server {
listen 8080;
server_name zzz;
rewrite ^ /blah break;
}

you should see something like this in error_log:

2009/12/10 15:50:19 [notice] 12343#0: *1 "^" matches "/", client: 127.0.0.1, server: zzz, request: "GET / HTTP/1.0"
2009/12/10 15:50:19 [notice] 12343#0: *1 rewritten data: "/blah", args: "", client: 127.0.0.1, server: zzz, request: "GET / HTTP/1.0"

If you don't see such messages - either you have no rewrites
defined in matching server{} block, or your set logging level
higher than notice.

Maxim Dounin

p.s. Please do not top-post. Thank your.

>
> On Thu, Dec 10, 2009 at 3:41 AM, Maxim Dounin <mdounin@mdounin.ru> wrote:
>
> > Hello!
> >
> > On Wed, Dec 09, 2009 at 09:22:32PM +0500, Ziyad Saeed wrote:
> >
> > > is there a rewrite log file that shows what is the rewrite engine doing,
> > > what is it trying to match and failing etc
> >
> > rewrite_log on;
> >
> > With this settings basic rewrite information will be logged to
> > error_log at notice level.
> >
> > Maxim Dounin
> >
> > _______________________________________ ________
> > nginx mailing list
> > nginx@nginx.org
> > http://nginx.org/mailman/listinfo/nginx
> >

> _______________________________________ ________
> nginx mailing list
> nginx@nginx.org
> http://nginx.org/mailman/listinfo/nginx

http://wiki.nginx.org/CoreModule
Цитировать
error_log

Syntax: error_log file [ debug | info | notice | warn | error | crit ]

Default: ${prefix}/logs/error.log

Specifies the file where server (and fastcgi) errors are logged.

Default values for the error level:

   1. in the main section - error
   2. in the HTTP section - crit
   3. in the server section - crit

Nginx supports separate error logging per virtual host. This is a unique feature, which lighttpd refuses to implement. For an example of separate error logging per server, see SeparateErrorLoggingPerVirtualHost and this mailing list thread on separating error logging per virtual host.

If you've built Nginx with --with-debug, you may also use:

error_log LOGFILE [debug_core | debug_alloc | debug_mutex | debug_event | debug_http | debug_imap];

Note that error_log off does not disable logging - the log will be written to a file named "off". To disable logging, you may use:

error_log /dev/null crit;

Also note that as of version 0.7.53, nginx will use a compiled-in default error log location until it has read the config file. If the user running nginx doesn't have write permission to this log location, nginx will raise an alert like this:

[alert]: could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
Записан

So it goes...
Страниц: [1]   Вверх
  Печать  
 
Перейти в:  

 ONLINECHANGE
Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!


Google visited last this page Декабрь 02, 2023, 00:03:04