博客正式从apache迁移至nginx

从apache迁移到nginx,主要有以下几个方面的事情:

1、编译php和nginx

编译php的参数:

./configure –prefix=/usr/local/php5 -with-config-file-path=/usr/local/php5/etc –enable-fpm –enable-pcntl –enable-mysqlnd –enable-opcache –enable-sockets –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-shmop –enable-zip –enable-ftp –enable-soap –enable-xml –enable-mbstring –disable-rpath –disable-debug –disable-fileinfo –with-mysql –with-mysqli –with-pdo-mysql –with-pcre-regex –with-iconv –with-zlib –with-mcrypt –with-gd –with-mhash –with-xmlrpc
make
make install

编译php关键的是要加–enable-fpm参数,因为nginx不像apache有php插件,可以直接调用php。nginx是通过fast-cgi连接php服务,php服务是通过fpm启动的,php的其它模块最好也编译进去,不知道wordpress会用到什么模块,否则又要重新编译。

编译nginx

./configure –prefix=/usr/local/nginx
make
make install

nginx 没有什么选项要指定,直接编译就好了。

2、启动php-fpm
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf

编辑配置文件:/usr/local/php5/etc/php-fpm.conf
一个是用户和群组:
user = zhaoyanblog
group = users

一个是端口
listen = 127.0.0.1:9000

最后启动就可以了:
/usr/local/php5/sbin/php-fpm

3、启动nginx

编辑配置文件:/usr/local/nginx/conf/nginx.conf
添加http选项,增加压缩选项:

gzip on;
	#启动压缩的最小报文大小
gzip_min_length 1k;
	#压缩所使用的缓存
gzip_buffers 4 16k;
	#压缩等级1表示最快,9表示最好
gzip_comp_level 2;
	#压缩支持的content-Type类型
gzip_types text/plain text/javascript application/x-javascript text/css text/xml application/xml application/xml+rss application/javascript;

里server里配置:

server {
	listen       80;
	server_name  zhaoyanblog.com;
	root   /home/zhaoyanblog/html;
	#wordpress的伪静态
	location / {
		index  index.php;
		if (-f $request_filename/index.html){
			rewrite (.*) $1/index.html break;
		}
		if (-f $request_filename/index.php){
			rewrite (.*) $1/index.php;
		}
		if (!-f $request_filename){
			rewrite (.*) /index.php;
		}
	}
	#fast-cgi连接php
	location ~ \.php$ {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;

	}

最后启动 /usr/local/nginx/sbin/nginx

留言

提示:你的email不会被公布,欢迎留言^_^

*

验证码 *