Events模块(Events Module)
·摘要
配置start/stop事件
示例配置:
on_start /opt/f.sh;
on_stop kill `cat /tmp/f.pid`;
on_stop rm -f /tmp/f.sock;
作者:Anton Dutov
下载该模块
源代码
文档:英文,俄文
·指令
on_start
语法:on_start <system command>
默认值:none
使用字段:server
示例:on_start echo “started” > /tmp/test && date >> /tmp/test;
在服务启动时执行一些系统命令。
on_stop
语法:on_stop <system command>
默认值:none
使用字段:server
示例:on_stop echo “stopped” > /tmp/test && date >> /tmp/test;
在服务停止时执行一些系统命令。
·示例配置
Mercurial (代理)
server {
listen 80;
server_name hg.dutov.org;
server_name_in_redirect off;
access_log /var/log/nginx/org.dutov.hg.access.log main;
on_start hg serve
--style paper
--webdir-conf /var/www/org.dutov.hg/org.dutov.hg.hgweb
--pid-file /var/run/org.dutov.hg.pid
-A /dev/null
-E /dev/null
-d -a 127.0.0.1 -p 8080;
on_stop kill `cat -- /var/run/org.dutov.hg.pid`;
on_stop rm -f -- /var/run/org.dutov.hg.pid;
location / {
if ($request_method = POST ) {
return 405;
}
proxy_pass http://127.0.0.1:8080/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 10m;
}
}
Redmine
server {
listen 80;
server_name dev.dutov.org;
server_name_in_redirect off;
access_log /var/log/nginx/org.dutov.dev.access.log main;
root /var/www/org.dutov.dev/public;
on_start export RAILS_ENV="production" && /usr/bin/spawn-fcgi
-u www-data
-g www-data
-P /var/run/org.dutov.dev.pid
-s /var/run/org.dutov.dev.sock
-f /var/www/org.dutov.dev/public/dispatch.fcgi;
on_stop kill `cat -- /var/run/org.dutov.dev.pid`;
on_stop rm -f -- /var/run/org.dutov.dev.pid;
location ~ ^/(javascripts|stylesheets|themes|images|help)/ {
expires 30d;
access_log off;
}
location / {
fastcgi_pass unix:/var/run/org.dutov.dev.sock;
include /etc/nginx/fastcgi_params;
}
}
·参考文档