Nginx
Versión |
1.2.4 |
Página principal |
http://wiki.nginx.org |
Observaciones |
Servidor proxy inverso y servidor web |
Sumario
Enlaces y referencias
- Ref: Blog de Martin Fjordvald
- Ref: Migrate from Apache to Nginx: The new guide
- Detalles de configuración:
Ejemplos
Transmission y otros
En el ejemplo se accede los siguientes recursos en el servidor:
- Programa transmission: http://torrents.home
- Programa de monitorización: http://torrents.home/monitorix
- Vista de carpeta de archivos descargados: http://torrents.home/downloads
# Configuración de servidor torrents.home # server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html; server_name torrents.home; location /monitorix { proxy_pass http://localhost:8080; } location /downloads { fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; fancyindex_hide_symlinks on; root /var/lib/transmission-daemon/; } location / { proxy_pass http://localhost:9091; } }
Recetario
Movable Type y Plack
En este caso concreto he terminado ejecutando el propio programa Movable Type bajo su propio entorno persistente empleando libplack-perl y ciertos ajustes en la configuración del mismo.
Para arrancar el gestor de blogs como servicio he tomado prestado el trabajo de ssahov y le he añadido algunas cosas.
#!/bin/sh
### BEGIN INIT INFO
# Provides: mt-starman
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Movable Type on starman daemon
# Description: Start and stop starman daemon for Movable Type
### END INIT INFO
#
# Default values for external defaults file
#
DIR=/opt/mt
SCRIPT=/opt/mt/mt.psgi
USER=www-data
GROUP=www-data
DAEMON=/usr/bin/starman
WORKERS=3
LISTEN=127.0.0.1:50000
# Try to load the defaults file
if [ -r /etc/default/mt-starman ]; then
source /etc/default/mt-starman
fi
# Common values
ERROR_LOG=/var/log/mt-starman.log
PIDDIR=/var/run/mt
PIDFILE="$PIDDIR/mt.pid"
# Check the logfile
if [ ! -e $ERROR_LOG ]; then
touch $ERROR_LOG
chown $USER:$GROUP $ERROR_LOG
fi
# Check the PID file because the program start without root privileges
if [ ! -e $PIDDIR ]; then
mkdir $PIDDIR
chown $USER:$GROUP $PIDDIR
fi
case "$1" in
start)
start-stop-daemon --start --chuid $USER --chdir $DIR \
--pidfile=$PIDFILE --background \
--exec $DAEMON -- --pid $PIDFILE \
--listen $LISTEN --error-log $ERROR_LOG \
--user $USER --group $GROUP \
--workers $WORKERS $SCRIPT
;;
stop)
start-stop-daemon --stop --pidfile $PIDFILE
;;
*)
echo "Usage: $SCRIPTNAME {start|stop}" >&2
exit 3
;;
esac
Este script, compatible con la versión estable de Debian (Wheezy en este momento) puede utilizar un archivo de valores predefinidos en /etc/default/mt-starman.
Respecto al servidor nginx es necesario definir un recurso dentro de la sección http de su configuración. Se puede guardar en el directorio /etc/nginx/conf.d/starman.conf y deberá definir el siguiente contenido:
#
# Definición del backend starman
#
upstream starman {
server 127.0.0.1:50000;
}
En la definición del servidor virtual (en mi caso así lo he dispuesto) se necesita indicar a Movable Type dónde usar dicho recurso:
server {
listen 80;
server_name esferas.org;
root /var/virtual/esferas.org;
access_log /var/log/virtual/esferas.org/access.log;
error_log /var/log/virtual/esferas.org/error.log;
location / {
root /var/virtual/esferas.org;
index index.html index.htm;
}
location /mt/ {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://starman;
}
}
fastCGI
- Ref: FcgiWrap
En Debian se debe instalar el paquete fcgiwrap para disponer de un entorno de ejecución FastCGI. Es un programa ligero y austero en recursos que apenas tiene configuración.
#
# /etc/default/fcgiwrap
#
# Number of instances to launch
DAEMON_OPTS="-c 3"
# Socket location
FCGI_SOCKET="/var/run/fcgiwrap.socket"
# User and group for the daemon processes
FCGI_USER="www-data"
FCGI_GROUP="www-data"