`
haoningabc
  • 浏览: 1445461 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

nginx运行php

阅读更多
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc mysql mysql-server mysql-devel

参考http://hi.baidu.com/zlflashlight/blog/item/3caa972224d634ffd6cae2b9.html
http://wenku.baidu.com/view/c3828ac4bb4cf7ec4afed0b4.html

今天配置了以下,在ubuntu上
http://www.imagemagick.org/script/index.php
nginx配置
user www-data;
#user  nobody;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
	autoindex on; 
	autoindex_exact_size off; 
	autoindex_localtime on; 
	default_type application/octet-stream; 
	sendfile on; 
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 10;
	gzip on;
	gzip_min_length 1k;
	gzip_buffers 4 8k;
	gzip_http_version 1.1;
	gzip_comp_level 3;
	gzip_types text/css text/xml text/plain application/x-javascript application/xml application/pdf application/rtf application/x-perl application/x-tcl application/msword application/vnd.ms-excel application/vnd.ms-powerpoint application/vnd.wap.xhtml+xml image/x-ms-bmp;
#	gzip_disable "MSIE [1-6] \.";
	gzip_vary on;
	output_buffers 4 32k;
	client_max_body_size 20m;
	server {
		listen       80;
		server_name  localhost;
		charset utf-8,gb2312;
		access_log /home/ubuntu/log/access.log;
		location / {
			root   /home/ubuntu/www;
			index  index.html index.htm index.php;
		}

		location ~ \.php$ { 
			fastcgi_pass 127.0.0.1:9000;
			fastcgi_index index.php;
			set $path_info "/";
			set $real_script_name $fastcgi_script_name;
			if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1;
				set $path_info $2;
			} 
		} 
		location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { 
			root /home/ubuntu/www;
			access_log off;
			expires 30d;
		} 
		location ~ .*\.(js|css|ico)?$ { 
			root /home/ubuntu/www;
			access_log off;
			expires 1h;
		} 
		error_page 500 502 503 504 /50x.html;
		location = /50x.html { 
			root /home/ubuntu/www;
		} 
		fastcgi_param SCRIPT_FILENAME /home/ubuntu/www/$real_script_name;
		fastcgi_param script_name $real_script_name;
		fastcgi_param path_info $path_info;
		include /usr/local/openresty/nginx/nginx/conf/fastcgi_params; 
	}
}

nginx前需要启动fastcgi
root@li408-34:/usr/local/openresty/nginx/nginx# cat fast.sh 
#!/bin/sh
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
root@li408-34:/usr/local/openresty/nginx/nginx# 

i好奇怪的是spawn-fcgi是需要装lighttpd后才有的


如果是在fedora 7下 测试页面
[root@fedora17 html]# cat index.php 
<?php  phpinfo(); ?>
[root@fedora17 html]# pwd
/usr/local/nginx/html
[root@fedora17 html]# 


yum install spawn-fcgi
yum install php

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid


配置文件
[root@fedora17 conf]# cat nginx.conf
user www-data;
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
	autoindex on; 
	autoindex_exact_size off; 
	autoindex_localtime on; 
	default_type application/octet-stream; 
	sendfile on; 
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 10;
	gzip on;
	gzip_min_length 1k;
	gzip_buffers 4 8k;
	gzip_http_version 1.1;
	gzip_comp_level 3;
	gzip_types text/css text/xml text/plain application/x-javascript application/xml application/pdf application/rtf application/x-perl application/x-tcl application/msword application/vnd.ms-excel application/vnd.ms-powerpoint application/vnd.wap.xhtml+xml image/x-ms-bmp;
#	gzip_disable "MSIE [1-6] \.";
	gzip_vary on;
	output_buffers 4 32k;
	client_max_body_size 20m;
	server {
		listen       80;
		server_name  192.168.76.138;
		charset utf-8,gb2312;
		access_log /home/ubuntu/log/access.log;
		location / {
			root   html;
			index  index.html index.htm index.php;
		}

		location ~ \.php$ { 
			fastcgi_pass 127.0.0.1:9000;
			fastcgi_index index.php;
			set $path_info "/";
			set $real_script_name $fastcgi_script_name;
			if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1;
				set $path_info $2;
			} 
		} 
		location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { 
			root html;
			access_log off;
			expires 30d;
		} 
		location ~ .*\.(js|css|ico)?$ { 
			root html;
			access_log off;
			expires 1h;
		} 
		error_page 500 502 503 504 /50x.html;
		location = /50x.html { 
			root html;
		} 
		fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
		fastcgi_param script_name $real_script_name;
		fastcgi_param path_info $path_info;
		include /usr/local/nginx/conf/fastcgi_params; 
	}
}

[root@fedora17 conf]# 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics