日期:2014-05-16  浏览次数:20831 次

debian 下安装切换apache到nginx,php5-fpm和spawn-cgi运行php

1:前言

 以前debian作开发机server是apache,工作需要切换到nginx,有时候两个都要使用。作个简单的笔记。注意,本文仅仅是在debian 7(wheezy) 上。其它OS有其它OS的配置和安装,不能保证一致性。apache的安装配置就参考前面发的文章了。


2:安装 nginx  php5-cgi php5-fpm spawn-fcgi 

#apt-get install nginx nginx-full nginx-common php5-cgi php5-fpm spawn-fcgi


3:配置各个的php.ini 

可以#cd /etc/php5 里面看见,

/etc/php5/apache2/php.ini   

/etc/php5/cgi/php.ini 

/etc/php5/cli/php.ini 

/etc/php5/fpm/php.ini 分别对应不同的php.ini 配置

#vim /etc/php5/cgi/php.ini  去掉cgi.fix-pathinfo=1 的注释


4:配置nginx.conf

在/etc/nginx/nginx.conf

把下面的复制进去, 或者你可以对比下修改

user www-data;
worker_processes 12;
pid /var/run/nginx.pid;

worker_rlimit_nofile 51200;
events {
	worker_connections 30760;
	# multi_accept on;
}

http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 60;
	types_hash_max_size 2048;
	client_max_body_size 80m;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	fastcgi_connect_timeout 300;
	fastcgi_send_timeout 300;
	fastcgi_read_timeout 300;
	fastcgi_buffer_size 64k;
	fastcgi_buffers 4 64k;
	fastcgi_busy_buffers_size 128k;
	fastcgi_temp_file_write_size 128k;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	gzip_vary on;
	gzip_min_length 1k;
	# gzip_proxied any;
	gzip_comp_level 2;
	gzip_buffers 4 16k;
	gzip_http_version 1.1;
	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

	##
	# nginx-naxsi config
	##
	# Uncomment it if you installed nginx-naxsi
	##

	#include /etc/nginx/naxsi_core.rules;

	##
	# nginx-passenger config
	##
	# Uncomment it if you installed nginx-passenger
	##
	
	#passenger_root /usr;
	#passenger_ruby /usr/bin/ruby;

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}


#mail {
#	# See sample authentication script at:
#	# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#	# auth_http localhost/auth.php;
#	# pop3_capabilities "TOP" "USER";
#	# imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#	server {
#		listen     localhost:110;
#		protocol   pop3;
#		proxy      on;
#	}
# 
#	server {
#		listen     localhost:143;
#		protocol   imap;
#		proxy      on;
#	}
#}




5: 配置default

在/etc/nginx/sites-available/default, 注意,下面我的配置文件写了两个 注释掉了  php5-cgi  的, 打开了php5-fpm的。 我这里用的是php5-fpm

如果你需要用spawn-fcgi,就需要php5-cgi 加########的那段。/home/www 是我的www目录。你可以对着改成你的www目录。root  /home/www 这里也是。 我打开了自动索引,autoindex这个。

# You may add here your
# server {
#	...
# }
# statements for each of your virtual hosts to this file

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Ngin