7月 212016
 

最近好几个朋友在给网站开启 HTTP/2 后,都遇到了无法访问的问题。其中有的网站只是 Firefox 无法访问,通过控制台网络面板可以看到请求被 Abort;有的网站不但 Firefox 无法访问,连 Chrome 也会跳到错误页,错误代码是「ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY」。诡异的是,只要去掉对 HTTP/2 的支持(例如去掉 Nginx listen 配置中的 http2)就一切正常。也就是说无法访问的现象只存在于 HTTPS + HTTP/2 的组合,单独提供 HTTPS 服务时就是好的。

这个问题比较有趣,本文除了告诉大家如何解决它之外,还会帮助大家弄清问题的来龙去脉。如果你只关心结论,直接看最后的小结即可。 Continue reading »

6月 042016
 

前提:已经拥有域名证书,且服务器支持添加SSL证书(如VPS或云主机,以及部分虚拟主机)

虽然DiscuzX3.2已经针对https做了优化,但仍有很多地方需要改动,经过在几个生产环境的改造中发现,Discuz目前可以完美支持https并显示绿色https图标,不过有些麻烦,且每个环境都会出现自己的问题。

第一步:
全局 > 站点信息 > 网站 URL,修改为https://bolg.yibadao.net/的格式

第二步:修成Discuz适配https
如果你的Web服务是Apache,请忽略这一步,Nginx请继续看:
Discuz判断网站是否启动SSL是采用 $_SERVER[‘HTTPS’] 的方式,此方法不支持Nginx(nginx+php-fpm),需要先做一些修改,让Discuz使用 $_SERVER[‘SERVER_PORT’]来判断网站是否启用SSL。 Continue reading »

6月 122014
 

Most administrators know that PHP, the widely used scripting language, can be embedded in HTML and works with all major web servers. What’s less widely known, however is that you can run PHP in different ways on your server. The most common option is the mod_php module that’s runs by default in the Apache HTTP Server. If your primarily goal is performance, however, you should consider other options. PHP-FPM (FastCGI Process Manager) and PHP FastCGI each have pros and cons, but either can speed up the performance of your PHP.

mod_php

Let’s start by looking at running Apache with mod_php. This package is present in just about every Linux distribution’s repository, so installing it is easy, and so is configuring and managing the software. In fact, its ease of use may be the main reason to deploy mod_php.

With mod_php the PHP interpreter is “embedded” inside the Apache process; Apache doesn’t call any external PHP process, which means that Apache and PHP can communicate better. However, every single Apache child must load mod_php, which results in a bigger process than necessary being used for serving static resources such as image files, CSS, and JavaScript.

Another problem with this method is that it works only on Apache. This is not always an issue, as Apache is the most complete web server you can find, but websites that run on small virtual private servers (VPS), or big sites that have to serve million of pages a day, might want a different web server that can scale up or down better than Apache, and would therefore need a different way to run PHP too.

Pros:

  • Easy to install and update.
  • Easy to configure with Apache.

Cons:

  • Works only with Apache.
  • Forces every Apache child to use more memory.
  • Needs a restart of Apache to read an updated php.ini file.

Continue reading »

6月 122014
 

我在网上查fastcgi与php-fpm的关系,查了快一周了,基本看了个遍,真是众说纷纭,没一个权威性的定义。

网上有的说,fastcgi是一个协议,php-fpm实现了这个协议; 有的说,php-fpm是fastcgi进程的管理器,用来管理fastcgi进程的; 有的说,php-fpm是php内核的一个补丁; 有的说,修改了php.ini配置文件后,没办法平滑重启,所以就诞生了php-fpm; 还有的说PHP-CGI是PHP自带的FastCGI管理器,那这样的话干吗又弄个php-fpm出来,我就更晕了;

发个贴,想听听大家的理解,网上的我都已经看了个遍,因为我查了一周了,哈哈,所以想听听原创的理解。
======
刚开始对这个问题我也挺纠结的,看了《HTTP权威指南》后,感觉清晰了不少。

首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的, Continue reading »

12月 242013
 

In our first installation in this blog, we went through a basic XCache installation with CentOS, Apache and PHP 5. Now, we’re going to look into how to make it work for your personal installation.

Much like every other tutorial out there, if you explicitly follow the instructions you find on the internet, you’re usually going to run into problems. One of the biggest problems I see in systems configurations, is getting someone that “tunes” the machine by copying and pasting configs straight from a forum or blog. Sure, it works, but that doesn’t mean it works *good*. It could also cause many more problems that it solves.

The best way to tune a machine will always be understanding what you’re doing. And that’s what we’re going to try to do here today with XCache. Continue reading »

12月 242013
 

有时候,运行 Nginx、PHP-CGI(php-fpm) Web服务的 Linux 服务器,突然系统负载上升,使用 top 命令查看,很多 php-cgi 进程 CPU 使用率接近100%。后来,我通过跟踪发现,这类情况的出现,跟 PHP 的 file_get_contents() 函数有着密切的关系。

们知道,在 php.ini 中,有一个参数 max_execution_time 可以设置 PHP 脚本的最大执行时间,但是,在 php-cgi(php-fpm) 中,该参数不会起效。真正能够控制 PHP 脚本最大执行时间的是 php-fpm.conf 配置文件中的以下参数: Continue reading »

12月 242013
 

http://blog.csdn.net/chen3888015/article/details/7432868

在 Linux 下 top 工具可以显示 cpu 的平均利用率(user,nice,system,idle,iowait,irq,softirq,etc.),可以显示每个 cpu 的利用率。但是无法显示每个线程的 cpu 利用率情况,
这时就可能出现这种情况,总的 cpu 利用率中 user 或 system 很高,但是用进程的 cpu 占用率进行排序时,没有进程的 user 或 system 与之对应。

可以用下面的命令将 cpu 占用率高的线程找出来:
 ps H -eo user,pid,ppid,tid,time,%cpu,cmd –sort=%cpu

这个命令首先指定参数’H’,显示线程相关的信息,格式输出中包含:user,pid,ppid,tid,time,%cpu,cmd,然后再用%cpu字段进行排序。这样就可以找到占用处理器的线程了。 Continue reading »

2月 272013
 

OpenVZ的VPS,装的ubunt 12.04,apache+fcgid+php,内存耗尽,php5-cgi进程陆续死掉。
apache error log 如下:

[Tue Feb 26 23:03:04 2013] [error] [client 218.2.173.196] File does not exist: /
var/www/default/cert
[Tue Feb 26 23:28:59 2013] [error] mod_fcgid: process /usr/bin/php5-cgi(26476) e
xit(communication error), get unexpected signal 11

Fatal error: Out of memory (allocated 0) (tried to allocate 8192 bytes) in Unkno
wn on line 0
[Tue Feb 26 23:29:11 2013] [error] (12)Cannot allocate memory: mod_fcgid: can't
run /usr/bin/php5-cgi Continue reading »