寻觅生命中的那一片浅草......

文章属于类别 应用软件

PHP程序页面打开空白

已经遇到过两次了,打开一片空白,没有任何提示。

1次是Discuz!首页打开时一片空白,但UCenter又可以打开,登录进后台stat index.php,发现文件的修改日期有问题,被修改日期是6月16日,论坛改版做好后,很久没有修改过这些文件了。估计是被人入侵了!网上有说是编码问题。难道别人把我文件的编码修改了?查看了下备份目录,刚好在6月13日有个备份,把它解压缩出来,覆盖掉原来的,一切恢复正常。

2次是朋友的一个很简单的站,打开是一个空白页面,对比过配置文件,发现跟其他站点的配置一样,怀疑会不会是程序不能在二级目录下运行,就把该主机的根目录设置为那二级目录,结果打开还是不行,又改回来,查看了Nginx的日志,没有错。最后去程序官方,重新下载了一个,直接在服务器上解压缩,再访问,一切正常。注意啊!估计是从Windows传文件上去时,文件出现的问题。无论是SFTP还是FTP,都记得要用binary(二进制)方式上传。这样是最保险的!

Nginx 502错误排查

NGINX 502 Bad Gateway错误是FastCGI有问题,造成NGINX 502错误的可能性比较多。将网上找到的一些和502 Bad Gateway错误有关的问题和排查方法列一下,先从FastCGI配置入手:

1.查看FastCGI进程是否已经启动
NGINX 502错误的含义是sock、端口没被监听造成的。我们先检查fastcgi是否在运行

2.检查系统Fastcgi进程运行情况
除了第一种情况,fastcgi进程数不够用、php执行时间长、或者是php-cgi进程死掉也可能造成nginx的502错误
运行以下命令判断是否接近FastCGI进程,如果fastcgi进程数接近配置文件中设置的数值,表明worker进程数设置太少
netstat -anpo | grep “php-cgi” | wc -l

3.FastCGI执行时间过长
根据实际情况调高以下参数值
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

4.头部太大
nginx和apache一样,有前端缓冲限制,可以调整缓冲参数
fastcgi_buffer_size 32k;
fastcgi_buffers 8 32k;
如果你使用的是nginx的负载均衡Proxying,调整
proxy_buffer_size  16k;
proxy_buffers      4 16k;
参见:http://www.ruby-forum.com/topic/169040

5.https转发配置错误
正确的配置方法
server_name www.mydomain.com;
location /myproj/repos {
set $fixed_destination $http_destination;
if ( $http_destination ~* ^https(.*)$ )
{
set $fixed_destination http$1;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Destination $fixed_destination;
proxy_pass http://subversion_hosts;
}
参见:http://www.ruby-forum.com/topic/169040

当然,还要看你后端用的是哪种类型的FastCGI,我用过的有php-fpm,流量约为单台机器40万PV(动态页面), 现在基本上没有碰到502。

转载自:http://www.jefflei.com/post/1049.html

同时连接数需求量计算公式

记不清是从那位兄弟伙的blog中看到这个公式,觉得很有用

每日PV数 / 86400秒 * 10个派生连接数 * 5秒内响应 * 5倍峰值) / Web服务器台数 = 同时连接数

转载自:http://www.ynog.com/index.php/archives/296

摸索了个nginx 502 Bad Gateway 的一种解决方法

昨天装上nginx后在高负载的时候,论坛上传图片或者执行较长时间脚本的时候就不停的

出现502 Bad Gateway ,网上搜了,大多数都是张大师的那篇解决方案,他的解决方案


http
{
……
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
……
}
增加了fastcgi的相应请求时间。但是我在实际中碰到了这个问题,设置到500,还是会出

现,只是比我设置120的时候要少一些。后来发现主要是在一些post或者数据库操作的时

候出现这种情况,静态页面是不会出现的。
反复的查问题,调试,也加大了CGI的进程数。
<value name=”max_children”>128</value>
256再加上去可能会变得很慢。占用内存大了。
在php-fpm.conf设置中还有一项,可能当时没注意到,无意中改了这个值。
request_terminate_timeout
这个值是max_execution_time,就是fast-cgi的执行脚本时间。
<value name=”request_terminate_timeout”>0s</value>
0s为关闭,就是无限执行下去。(当时装的时候没仔细看就改了一个数字)
发现,问题解决了,执行很长时间也不会出错了。
优化fastcgi中,还可以改改这个值<value

name=”process_control_timeout”>5s</value> 。看看效果
终于发现502的错误其实不是nginx的问题,哈哈
php-cgi进程数不够用、php执行时间长、或者是php-cgi进程死掉,都会出现502错误

转载自:http://blog.nowans.com/content/log.2008.10.29.229.html

chroot环境下Postfix的一些问题

ispCP装好后,没用过它的邮局功能,那天在CentOS5.3上安装了,发现不能发邮件,记得之前在CentOS5.2上装,新开主机什么的都可以发邮件的,经过一番折腾,发现CentOS5.2上能发,是因为它用的是sendmail,CentOS5.3上则是用Postfix,为解燃眉之急,只能把CentOS5.3上的Postfix停掉,启用sendmail,发信正常。

前天专门再装了台测试机,用来测试邮局功能。下面先贴下默认情况下,发信收信时,maillog的一些错误,日志中的邮箱地址和IP地址均已被替换。

测试时,首先把sendmail关掉
chkconfig –level 2345 sendmail off
service sendmail stop

然后开启相关邮局服务

maillog的内容

#################################################
Jun 20 13:32:16 test.com postfix/smtpd[318]: warning: connect to 127.0.0.1:12525: Connection refused
Jun 20 13:32:16 test.com postfix/smtpd[318]: warning: problem talking to server 127.0.0.1:12525: Connection refused
Jun 20 13:32:17 test.com postfix/smtpd[318]: warning: connect to 127.0.0.1:12525: Connection refused
Jun 20 13:32:17 test.com postfix/smtpd[318]: warning: problem talking to server 127.0.0.1:12525: Connection refused
Jun 20 13:32:17 test.com postfix/smtpd[318]: NOQUEUE: reject: RCPT from unknown[125.77.233.210]: 451 4.3.5 Server configuration problem; from=<root@debian.ispcp.net> to=<user@example.net> proto=ESMTP helo=<debian.ispcp.net>
Jun 20 13:32:17 test.com postfix/smtpd[318]: disconnect from unknown[125.77.233.210]
Jun 20 21:35:37 test.com postfix/anvil[319]: statistics: max connection rate 1/60s for (smtp:125.77.233.210) at Jun 20 21:32:16
Jun 20 13:35:37 test.com postfix/anvil[319]: statistics: max connection count 1 for (smtp:125.77.233.210) at Jun 20 13:32:16
Jun 20 13:35:37 test.com postfix/anvil[319]: statistics: max cache size 1 at Jun 20 13:32:16
Jun 20 21:36:00 test.com imapd: Connection, ip=[::ffff:127.0.0.1]
Jun 20 21:36:00 test.com imapd: LOGIN, user=user@example.net, ip=[::ffff:127.0.0.1], port=[48051], protocol=IMAP
Jun 20 21:36:00 test.com imapd: LOGOUT, user=user@example.net, ip=[::ffff:127.0.0.1], headers=0, body=0, rcvd=87, sent=391, time=0
Jun 20 21:37:01 test.com spamd[500]: logger: removing stderr method
Jun 20 21:37:08 test.com spamd[502]: spamd: server started on port 783/tcp (running version 3.2.5)
Jun 20 21:37:08 test.com spamd[502]: spamd: server pid: 502
Jun 20 21:37:08 test.com spamd[502]: spamd: server successfully spawned child process, pid 507
Jun 20 21:37:08 test.com spamd[502]: spamd: server successfully spawned child process, pid 508
Jun 20 21:37:08 test.com spamd[502]: prefork: child states: II
Jun 20 21:37:39 test.com postfix/smtpd[511]: connect from unknown[127.0.0.1]
Jun 20 13:37:39 test.com postfix/smtpd[511]: NOQUEUE: reject: RCPT from unknown[127.0.0.1]: 450 4.1.2 <user@example.com>: Recipient address rejected: Domain not found; from=<user@example.net> to=<user@example.com> proto=ESMTP helo=<11.22.33.44>
Jun 20 13:37:39 test.com postfix/smtpd[511]: lost connection after RCPT from unknown[127.0.0.1]
Jun 20 13:37:39 test.com postfix/smtpd[511]: disconnect from unknown[127.0.0.1]
Jun 20 13:37:41 test.com postfix/smtpd[511]: connect from unknown[127.0.0.1]
Jun 20 13:37:41 test.com postfix/smtpd[511]: NOQUEUE: reject: RCPT from unknown[127.0.0.1]: 450 4.1.2 <user@example.com>: Recipient address rejected: Domain not found; from=<user@example.net> to=<user@example.com> proto=ESMTP helo=<11.22.33.44>
Jun 20 13:37:41 test.com postfix/smtpd[511]: lost connection after RCPT from unknown[127.0.0.1]
Jun 20 13:37:41 test.com postfix/smtpd[511]: disconnect from unknown[127.0.0.1]
Jun 20 13:38:14 test.com postfix/smtpd[511]: connect from unknown[125.77.233.210]
Jun 20 13:38:14 test.com postfix/smtpd[511]: warning: connect to 127.0.0.1:12525: Connection refused
Jun 20 13:38:14 test.com postfix/smtpd[511]: warning: problem talking to server 127.0.0.1:12525: Connection refused
Jun 20 21:38:14 test.com postfix/smtpd[516]: connect from unknown[125.77.233.210]
Jun 20 13:38:14 test.com postfix/smtpd[516]: warning: connect to 127.0.0.1:12525: Connection refused
Jun 20 13:38:14 test.com postfix/smtpd[516]: warning: problem talking to server 127.0.0.1:12525: Connection refused
Jun 20 13:38:15 test.com postfix/smtpd[511]: warning: connect to 127.0.0.1:12525: Connection refused
Jun 20 13:38:15 test.com postfix/smtpd[511]: warning: problem talking to server 127.0.0.1:12525: Connection refused
Jun 20 13:38:15 test.com postfix/smtpd[511]: NOQUEUE: reject: RCPT from unknown[125.77.233.210]: 451 4.3.5 Server configuration problem; from=<root@debian.ispcp.net> to=<user@example.net> proto=ESMTP helo=<debian.ispcp.net>
Jun 20 13:38:15 test.com postfix/smtpd[511]: disconnect from unknown[125.77.233.210]
Jun 20 13:38:15 test.com postfix/smtpd[516]: warning: connect to 127.0.0.1:12525: Connection refused
Jun 20 13:38:15 test.com postfix/smtpd[516]: warning: problem talking to server 127.0.0.1:12525: Connection refused

#################################################

Jun 20 23:51:18 test.com postfix/postfix-script: starting the Postfix mail system
Jun 20 23:51:18 test.com postfix/master[6161]: daemon started — version 2.3.3, configuration /etc/postfix
Jun 20 23:51:18 test.com postfix/qmgr[6164]: C8FB618A830B: from=<xxx@dddf.com>, size=331, nrcpt=1 (queue active)
Jun 20 23:51:18 test.com postfix/smtp[6166]: fatal: unknown service: smtp/tcp
Jun 20 23:51:19 test.com postfix/qmgr[6164]: warning: premature end-of-input on private/smtp socket while reading input attribute name
Jun 20 23:51:19 test.com postfix/qmgr[6164]: warning: private/smtp socket: malformed response
Jun 20 23:51:19 test.com postfix/qmgr[6164]: warning: transport smtp failure — see a previous warning/fatal/panic logfile record for the problem description
Jun 20 23:51:19 test.com postfix/master[6161]: warning: process /usr/libexec/postfix/smtp pid 6166 exit status 1
Jun 20 23:51:19 test.com postfix/master[6161]: warning: /usr/libexec/postfix/smtp: bad command startup — throttling
Jun 20 23:51:19 test.com postfix/qmgr[6164]: C8FB618A830B: to=<user@example.com>, relay=none, delay=1708, delays=1707/1/0/0, dsn=4.3.0, status=deferred (unknown mail transport error)

好了,关键出错日志都贴出来了,下面讲解决办法

1、connect to 127.0.0.1:12525: Connection refused

输入命令netstat -aln | grep 12525
发现确实没有12525的监听程序

我们在/etc/postfix/main.cf可以看到一段配置:
smtpd_recipient_restrictions = reject_non_fqdn_recipient,
reject_unknown_recipient_domain,
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination,
reject_unlisted_recipient,
check_policy_service inet:127.0.0.1:12525,
check_policy_service inet:127.0.0.1:60000,

check_policy_service inet:127.0.0.1:12525
这一行是配置使用policyd-weight来进行垃圾邮件判别的,CentOS上默认没有装,但在debian5.0.1上装ispCP,默认是安装policyd-weight的
详细可以参考以下这个网址:

http://www.policyd-weight.org/

解决办法

a、安装policyd-weight,然后启用它
安装可以参考这篇文章:http://www.187299.com/archives/1044

b、把policyd-weight相关配置注释掉
把/etc/postfix/main.cf里相应配置注释掉,修改为如下:
#                               check_policy_service inet:127.0.0.1:12525,
#                               check_policy_service inet:127.0.0.1:60000,
service postfix restart重启服务。

2、Recipient address rejected: Domain not found
chroot环境下,Postfix不能用/etc/resolv.conf来进行域名解析,所以说Domain not found

解决办法:
cp /etc/resolv.conf /var/spool/postfix/etc/

处理到这一步,能达到的效果是Postfix能收不能发,也就是可以收到外部发给本地的邮件,但本地还不能发邮件给外面。

3、fatal: unknown service: smtp/tcp
跟第二个问题一样,chroot环境下,Postfix不能使用/etc/services

解决办法:
cp /etc/services /var/spool/postfix/etc/

至此,将邮局相应服务启动起来就可以进行邮件收发了。

知识备忘
/etc/postfix/master.cf
# service type  private unpriv  chroot  wakeup  maxproc command + args
smtp   inet     n       –       –       –       –       smtpd

这里对各种服务进行定义,如果是-或者y,则表示为真,所以以上关于smtp的配置,就是运行在chroot环境下。

网上很多文章都建议不要在chroot环境下运行Postfix,因为Postfix本来已经是一个非常健壮的MTA
有时间再研究下怎样设置Postfix在chroot环境下的根目录,再看如何把它改为普通环境运行。

2025年五月
« 5月    
 1234
567891011
12131415161718
19202122232425
262728293031