文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>在Gentoo上搭建nginx+php+mysql高并发环境

在Gentoo上搭建nginx+php+mysql高并发环境

时间:2008-11-07  来源:keelort

嘿嘿,我正在搞,遇到很多莫名奇妙的问题。先弄个显眼的标题,大家来添砖加瓦啊。

Nginx ("engine x")是 一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。尽管还是测试版,但是,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。

但是,Nginx在国内引起广泛关注应该归功于这篇文章Nginx 0.5.31 + PHP 5.2.4(FastCGI)搭建可承受3万以上并发连接数,胜过Apache 10倍的Web服务器。
蓝色文字[/color]

提供几个gentoo平台上的nginx资料

1。Nginx, WordPress & fun
http://www.dead-end.info/2007/08/26/nginx-wordpress-fun

2。Nginx, Fastcgi, PHP, rewrite config for Drupal
http://drupal.org/node/110224

3。Nginx with PHP as FastCGI on Gentoo Linux
http://www.tummblr.com/linux/nginx-w...-gentoo-linux/

自己瞎弄了两天,总算整了出来,nginx这丫的设置太陌生了,真郁闷 。先写到这里,希望大家多修正完善。完备了说不定还可以进wiki呢,嘿嘿。

安装与设置:
nginx部署一般都是从源码编译安装,方便自由定制。而gentoo特有的USE则可充分利用起来,让nginx安装更加便捷。

1. USE设置
代码:
www-servers/nginx fastcgi status
dev-lang/php mysql cgi curl discard-path force-cgi-redirect threads bzip2 gd
www-servers/lighttpd fastcgi
dev-db/mysql perl ssl
如果你想用新版的nginx请编辑/etc/portage/pakeage.keywords,加入 “
代码:
www-servers/lighttpd fastcgi php mysql ~x86
2.设置/etc/nginx/nginx.conf 列表比较长,自己添加了中文注释。

代码:
user nginx nginx;

worker_processes 1;error_log /var/log/nginx/error_log info;

events {

use epoll;

worker_connections 1024;

}

#设置http服务器及反向代理功能负载

http {

include /etc/nginx/mime.types;

default_type application/octet-stream;

#日志格式

log_format main

'$remote_addr - $remote_user [$time_local] '

'"$request" $status $bytes_sent '

'"$http_referer" "$http_user_agent" '

'"$gzip_ratio"';

log_format download '$remote_addr - $remote_user [$time_local] '

'"$request" $status $bytes_sent '

'"$http_referer" "$http_user_agent" '

'"$http_range" "$sent_http_content_range"';

# 设定请求缓冲&

client_header_buffer_size 1k;

large_client_header_buffers 4 4k;

client_header_timeout 10m;

client_body_timeout 10m;

send_timeout 10m;

connection_pool_size 256;

request_pool_size 4k;

#开启gzip

gzip on;

gzip_min_length 1100;

gzip_buffers 4 8k;

gzip_types text/plain;

output_buffers 1 32k;

postpone_output 1460;

sendfile on;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 75 20;

ignore_invalid_headers on;

#服务器设置

server {

listen 127.0.0.1;

server_name localhost;

access_log /var/log/nginx/localhost.access_log main;

error_log /var/log/nginx/localhost.error_log info;

#设定查看Nginx状态的地址

location /NginxStatus{

stub_status on;

access_log off;

allow 127.0.0.1;

# auth_basic "NginxStatus";

# auth_basic_user_file conf/htpasswd;

}

location / {

root /var/www/localhost/htdocs;

index index.html index.htm 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;

}

}

location ~ .*.php$

{

#fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs$fastcgi_script_name; 这个一定要设置,就是被这个浪费我很多时间。

}

}

##ssl portion

# server {

# listen 127.0.0.1:443;

# server_name localhost;

#

# ssl on;

# ssl_certificate /etc/ssl/nginx/nginx.pem;

# ssl_certificate_key /etc/ssl/nginx/nginx.key;

#

# access_log /var/log/nginx/localhost.ssl_access_log main;

# error_log /var/log/nginx/localhost.ssl_error_log info;

#

# root /var/www/localhost/htdocs;

# }

}
3。设置cgi,调用php
要在nginx上跑php,首先需要启动fastcgi,方法有三种,一是用php自带的fastcgi server,二是用lighttpd带的spawn-fcgi,三是用php-fpm。当然最好的是php-fpm.这个张宴的文里有个很好用的东东。 但是,郁闷的说gentoo里php的USE却没有 php-fpm项。我看了php的ebuild,头都大了,希望哪位能修改下贴出来。[url]http://php- fpm.anight.org[/url]
代码:
touch /usr/bin/php-fastcgi

vim /usr/bin/php-fastcgi
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -g www -f /usr/bin/php-cgi

touch /etc/init.d/init_fastcgi

vim /etc/init.d/init_fastcgi

#!/bin/bash
PHP_SCRIPT=/usr/bin/php-fastcgi
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php
RETVAL=$?
;;
restart)
killall -9 php
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL

chmod +x /usr/bin/php-fastcgi
chmod +x /etc/init.d/init_fastcgi
4.测试

/etc/init.d/init_fastcgi start

/etc/init.d/nginx start

然后写个phpinfo.php,http://127.0.0.1/phpinfo.php自己看看喽。 由于整个过程中换了几种方法连接cgi脚本,有些告混淆了,可能有些纰漏,请多多指教!另,我的wordpress还是有些页面会自动下载。rewrite规则有待完善。

更新日志:1.081015 11 添加 php-fastcgi
2. 加入php-fpm介绍。
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载