设为首页 收藏本站
查看: 554|回复: 0

[经验分享] nginx配置文件实例: php (fastcgi), perl, proxy, rrd, nagios

[复制链接]

尚未签到

发表于 2016-12-28 07:25:29 | 显示全部楼层 |阅读模式
  nginx.conf
  worker_processes 5;
  error_log logs/error.log;
error_log logs/error.log info;
  events {
use kqueue;
worker_connections 2048;
}
  http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 64;
  log_format main ‘$remote_addr – $remote_user [$time_local] $request ‘
‘”$status” $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;
  access_log logs/access.log main;
  sendfile on;
  keepalive_timeout 65;
  tcp_nopush on;
  upstream proxy {
server 192.168.0.2:80 weight=2;
server 192.168.0.3:80;
}
  server {
listen 80;
server_name my.example.com 192.168.0.1;
  access_log logs/my.example.com.access.log main;
  location /status {
stub_status on;
access_log off;
allow 192.168.0.1;
deny all;
}
  location / {
root /usr/local/www/status;
index index.php;
allow 192.168.100.1;
deny all;
}
  location ~ \.php$ {
fastcgi_pass unix:/tmp/php-fastcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/status$fastcgi_script_name;
include fastcgi_params;
}
  location /nagios {
root /usr/local/www;
allow 192.168.100.1;
deny all;
}
  location ~ \.cgi$ {
root /usr/local/www/nagios/cgi-bin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
fastcgi_index index.cgi;
allow 192.168.100.1;
deny all;
fastcgi_pass unix:/tmp/perl_cgi-dispatch.sock;
fastcgi_param HTTP_ACCEPT_ENCODING gzip,deflate;
fastcgi_param SCRIPT_FILENAME /usr/local/www/nagios/cgi-bin$fastcgi_script_name;
include fastcgi_params;
}
}
  server {
listen 80;
server_name proxy.example.com;
  access_log logs/proxy.example.com.access.log main;
  location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://proxy;
}
}
}
  nginx-rrd.conf
  #####################################################
#
# dir where rrd databases are stored
RRD_DIR=”/var/spool/nginx-rrd”;
# dir where png images are presented
WWW_DIR=”/usr/local/www/status”;
# process nice level
NICE_LEVEL=”-19″;
# bin dir
BIN_DIR=”/usr/sbin”;
# servers to test
# server_utl;server_name
SERVERS_URL=”http://my.example.com/status;my.example.com http://192.168.0.2/status;2″
  fastcgi-php (creates php fastcgi socket, executable init script for FreeBSD, can be ported easily to other systems)
  . /etc/rc.subr
  name=”fcgiphp”
rcvar=`set_rcvar`
  load_rc_config $name
  : ${fcgiphp_enable=”NO”}
: ${fcgiphp_bin_path=”/usr/local/bin/php-cgi”}
: ${fcgiphp_user=”www”}
: ${fcgiphp_group=”www”}
: ${fcgiphp_children=”10″}
: ${fcgiphp_port=”8002″}
: ${fcgiphp_socket=”/tmp/php-fastcgi.sock”}
: ${fcgiphp_env=”SHELL PATH USER”}
: ${fcgiphp_max_requests=”500″}
: ${fcgiphp_addr=”localhost”}
  pidfile=/var/run/fastcgi/fcgiphp.pid
procname=”${fcgiphp_bin_path}”
command_args=”/usr/local/bin/spawn-fcgi -f ${fcgiphp_bin_path} -u ${fcgiphp_user} -g ${fcgiphp_group} -C ${fcgiphp_children} -P ${pidfile}”
start_precmd=start_precmd
stop_postcmd=stop_postcmd
  start_precmd()
{
PHP_FCGI_MAX_REQUESTS=”${fcgiphp_max_requests}”
FCGI_WEB_SERVER_ADDRS=$fcgiphp_addr
export PHP_FCGI_MAX_REQUESTS
export FCGI_WEB_SERVER_ADDRS
allowed_env=”${fcgiphp_env} PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS”
# copy the allowed environment variables
E=”"
for i in $allowed_env; do
eval “x=\$i”
E=”$E $i=$x”
done
command=”env – $E”
  if [ -n "${fcgiphp_socket}" ]; then
command_args=”${command_args} -s ${fcgiphp_socket}”
elif [ -n "${fcgiphp_port}" ]; then
command_args=”${command_args} -p ${fcgiphp_port}”
else
echo “socket or port must be specified!”
exit
fi
}
  stop_postcmd()
{
rm -f ${pidfile}
#       eval “ipcs | awk ‘{ if (\$5 == \”${fcgiphp_user}\”) print \”ipcrm -s \”\$2}’ | /bin/sh”
}
  run_rc_command “$1″
  perl-fcgi.pl (creates perl socket) – you need the FCGI perl module for this
  #!/usr/bin/perl
  use FCGI;
#perl -MCPAN -e ‘install FCGI’
use Socket;
  #this keeps the program alive or something after exec’ing perl scripts
END() { } BEGIN() { }
*CORE::GLOBAL::exit = sub { die “fakeexit\nrc=”.shift().”\n”; }; eval q{exit}; if ($@) { exit unless $@ =~ /^fakeexit/; } ;
  &main;
  sub main {
#$socket = FCGI::OpenSocket( “:3461″, 10 ); #use IP sockets
$socket = FCGI::OpenSocket( “/tmp/perl_cgi-dispatch.sock”, 10 ); #use UNIX sockets – user running this script must have w access to the ‘nginx’ folde
r!!
$request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket );
if ($request) { request_loop()};
FCGI::CloseSocket( $socket );
}
  sub request_loop {
while( $request->Accept() >= 0 ) {
  #processing any STDIN input from WebServer (for CGI-POST actions)
$stdin_passthrough =”;
$req_len = 0 + $req_params{’CONTENT_LENGTH’};
if (($req_params{’REQUEST_METHOD’} eq ‘POST’) && ($req_len != 0) ){
while ($req_len) {
$stdin_passthrough .= getc(STDIN);
$req_len–;
}
}
  #running the cgi app
if ( (-x $req_params{SCRIPT_FILENAME}) &&  #can I execute this?
(-s $req_params{SCRIPT_FILENAME}) &&  #Is this file empty?
(-r $req_params{SCRIPT_FILENAME})     #can I read this file?
){
foreach $key ( keys %req_params){
$ENV{$key} = $req_params{$key};
}
#http://perldoc.perl.org/perlipc.html#Safe-Pipe-Opens
open $cgi_app, ‘-|’, $req_params{SCRIPT_FILENAME}, $stdin_passthrough or print(”Content-type: text/plain\r\n\r\n”); print “Error: CGI app ret
urned no output – Executing $req_params{SCRIPT_FILENAME} failed !\n”;
if ($cgi_app) {print <$cgi_app>; close $cgi_app;}
}
else {
print(”Content-type: text/plain\r\n\r\n”);
print “Error: No such CGI app – $req_params{SCRIPT_FILENAME} may not exist or is not executable by this process.\n”;
}
  }
}

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-320307-1-1.html 上篇帖子: nginx timeout 配置 全局timeout 局部timeout web timeout 下篇帖子: 关于nginx配置解析中merge操作的探讨
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表