LinuxSir.Org  
| 网站首页 | 注册账号 | 论坛帮助 |

欢迎来到LinuxSir.Org!
您还未登录,请登录后查看论坛,或者点击论坛上方的注册链接注册新账号。


发表新主题 回复
精华主题  
主题工具
旧 08-04-06, 14:25 第 1 帖
store88 帅哥
 
store88 的头像
 
 
注册会员  
  注册日期: Oct 2004
  我的住址: ZheJiang
  帖子: 122
  精华: 1
 

标题: [参考]搭建Nginx 0.5.35 + php 5.2.5 (ArchLinux)


前言:我是以尝鲜为主要目的,对于性能的测试实在不想搞,不过我一向以人家的测试报告为准的

代码:
pacman -S php
默认配置文件在/etc/php/php.ini

增加php5扩展模块
代码:
pacman -S gd vi /etc/php/php.ini
加入extension = "gd.so"

安装Zend Optimizer,到Zend官方网站下载相应CPU的版本,解压后运行./install
代码:
pacman -S php-eaccelerator vi /etc/php/php.ini
引用:
zend_extension=/usr/lib/php/20060613/eaccelerator.so
eaccelerator.shm_size=16
eaccelerator.cache_dir=/tmp/eaccelerator
eaccelerator.enable=1
eaccelerator.optimizer=1
eaccelerator.check_mtime=1
eaccelerator.debug=0
eaccelerator.filter=""
eaccelerator.shm_max=0
eaccelerator.shm_ttl=0
eaccelerator.shm_prune_period=0
eaccelerator.shm_only=0
eaccelerator.compress=1
eaccelerator.compress_level=9
引用:
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so
这两行搞到最后

创建web服务用户
代码:
groupadd www useradd -md /home/httproot -g www -p Insecure0 nginx chmod +w /home/httproot
代码:
pacman -S lighttpd
只是为了得到spawn-fcgi
启动php-cgi进程,监听127.0.0.1的10080端口,进程数为16,用户为nginx:
代码:
spawn-fcgi -a 127.0.0.1 -p 10080 -C 16 -u nginx -f php-cgi
代码:
pacman -S nginx
默认配置文件在/etc/nginx/conf/nginx.conf

代码:
vi /etc/nginx/conf/nginx.conf
引用:
user nginx;

worker_processes 10;

error_log logs/error.log crit;

#pid logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
{
use epoll;

worker_connections 51200;
}

http
{
include conf/mime.types;
default_type application/octet-stream;

charset gb18030;

server_names_hash_bucket_size 128;

#sendfile on;
#tcp_nopush on;

keepalive_timeout 60;

tcp_nodelay on;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/html application/xml;

server
{
listen 80;
server_name localhost;
index index.html index.php;
root /home/httproot;

if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}

location ~ .*\.php?$
{
root /home/httproot;
include conf/fastcgi_params;
fastcgi_pass 127.0.0.1:10080;
fastcgi_index index.php;
}

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data1/logs/access.log main;
}
启动Nginx
代码:
ulimit -SHn 51200 /etc/rc.d/nginx start
代码:
su nginx vi /home/httproot/index.php
PHP 代码:
<?php
phpinfo
();
?>
测试127.0.0.1

代码:
netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:10080 *:* LISTEN
tcp 0 0 *:cvspserver *:* LISTEN
tcp 0 0 *:http *:* LISTEN


优化Linux内核参数
代码:
vi /etc/sysctl.conf
引用:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000

使配置立即生效:
代码:
/sbin/sysctl -p
加入启动服务
代码:
vi /etc/rc.conf
引用:
DAEMONS=(................nginx);
代码:
vi /etc/profle
引用:
ulimit -SHn 51200
spawn-fcgi -a 127.0.0.1 -p 10080 -C 16 -u nginx -f php-cgi
任务结束了

参考文献:http://hi.baidu.com/vincent%5Fluo/bl...1b21bba6a.html
http://techpush.com/archives/install...slicehost-vps/

此帖于 08-04-14 00:40 被 store88 编辑.
  store88 当前离线   回复时引用此帖
旧 08-04-06, 15:44 第 2 帖
cwjiof
 
cwjiof 的头像
 
 
注册会员  
  注册日期: Mar 2006
  帖子: 624
  精华: 0
 

这么有意义的帖子,怎能不回?
  cwjiof 当前离线   回复时引用此帖
旧 08-04-06, 23:45 第 3 帖
jarryson 帅哥
 
jarryson 的头像
 
 
注册会员  
  注册日期: Jul 2004
  我的住址: 湖北武汉
  帖子: 5,670
  精华: 3
 

不错不错,支持







__________________
AMD Turion MT-34 1.8G,1G+256M ddr333,VIA,AMD-ATI X700 128M,160G IDE,15.4宽...

Archlinux -- 最新,最快,最方便
  jarryson 当前离线   回复时引用此帖
旧 08-04-13, 01:37 第 4 帖
gogonkt
 
gogonkt 的头像
 
 
注册会员  
  注册日期: Jul 2002
  帖子: 306
  精华: 0
 

不错,正需要
  gogonkt 当前离线   回复时引用此帖
旧 09-10-10, 20:57 第 5 帖
lwkyy
 
 
 
注册会员  
  注册日期: Aug 2006
  我的住址: 上海
  帖子: 124
  精华: 0
 

不懂为什么要通过安装 lighttpd 来得到spawn-fcgi,AUR中有个spawn-fcgi 1.6.3-1难到不能使用吗?

照的你方法安装好nginx后,没办法启动啊,所示如下:
代码:
:: Checking configuration [BUSY] [emerg]: getgrnam("nginx") failed in /etc/nginx/conf/nginx.conf:1 configuration file /etc/nginx/conf/nginx.conf test failed [FAIL]
这是怎么一回事,第一行是 user nginx;







__________________
IBM Thinkpad T43 2668-46U
Inter(R) Pentium(R) M processor 1.86GHz,
Inter 915PM, 2G DDR2, 40G ATA
14.1" TFT 1400x1050 LCD Screen,
64MB ATI Radeon X300

此帖于 09-10-10 21:35 被 lwkyy 编辑.
  lwkyy 当前离线   回复时引用此帖
旧 09-10-10, 21:04 第 6 帖
jqxl0205 帅哥
 
 
 
注册会员  
  注册日期: Dec 2007
  帖子: 468
  精华: 0
 

引用:
作者: lwkyy
不懂为什么要通过安装 lighttpd 来得到spawn-fcgi,AUR中有个spawn-fcgi 1.6.3-1难到不能使用吗?
因为那是aur里面的,ligghttpd是extra里面的。

如果用AUR中的spawn-fcgi的话,教程里面就要讲解aur和makepkg的知识(当然对archer来说,一般都知道aur)。







__________________
K.I.S.S

ArchLinux 2.6.35-bfs

此帖于 09-10-10 21:07 被 jqxl0205 编辑.
  jqxl0205 当前在线   回复时引用此帖
旧 09-10-10, 22:58 第 7 帖
lwkyy
 
 
 
注册会员  
  注册日期: Aug 2006
  我的住址: 上海
  帖子: 124
  精华: 0
 

我按这配置没办法成功,getgrnam("nginx")问题没办法解决,看了下张宴的配置过程,装nginx的user改用www后(建立了www用户httproot目录也给了www),nginx能启动起来了,测试个HTML文件也没问题,但测试php文件时就不行了,提示找不到404,郁闷。
  lwkyy 当前离线   回复时引用此帖
旧 09-10-12, 20:30 第 8 帖
lwkyy
 
 
 
注册会员  
  注册日期: Aug 2006
  我的住址: 上海
  帖子: 124
  精华: 0
 

我这里也出现了这样的问题,

WEB目录我设置为/home/httproot 目录的权限是700,
drwx------ 2 http http 4096 10月 11 02:05 httproot

问题是这样的:在浏览器里访问静态文件时正常,但一访问php文件时就无任何显示,看access.log文件得知访问都是500请求,而访问像html这样的文件时是正常的200。

nginx.conf设置是这样的
代码:
user http http; worker_processes 8; error_log logs/error.log crit; #pid logs/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; #charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; #access_log logs/access.log main; sendfile on; tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; 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 on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #vhosts settings include vhosts.conf; }
vhosts.conf文件配置是这样的:
代码:
server { listen 80; server_name localhost; index index.html index.php; root /home/httproot; autoindex on; #error_page 404 /404.html; location / { root /home/httproot; index index.html index.php; } location ~ .*\.php?$ { root /home/httproot; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; access_log /var/log/nginx/access.log main; }
看日志中error.log中没有任何输出,在access.log中的输出像这样的:
代码:
127.0.0.1 - - [11/Oct/2009:02:13:05 +0000] "GET /index.php HTTP/1.1" 500 5 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Chrome/4.0.221.8 Safari/532.2" -
在启动nginx之前我使用过如下命令:
代码:
spawn-fcgi -a 127.0.0.1 -p 9000 -c 16 -u http -f php-cgi
并提示成功!

感觉问题还是出在nginx与PHP之间的通信上,但不知如何解决。请高人教我看看!
  lwkyy 当前离线   回复时引用此帖
旧 09-11-01, 15:47 第 9 帖
gfreezy
 
 
 
注册会员  
  注册日期: Nov 2009
  帖子: 2
  精华: 0
 

默认php软件包不包含FastCGI,所以要安装下
sudo pacman -S php php-cgi
这样就可以了
  gfreezy 当前离线   回复时引用此帖
旧 09-11-01, 16:41 第 10 帖
cwjiof
 
cwjiof 的头像
 
 
注册会员  
  注册日期: Mar 2006
  帖子: 624
  精华: 0
 

顶楼写文的时候,确实是包含 FastCGI 的,但后来 php 和 php-cgi 被分成两个包了,原因当然是 KISS,呵呵。
  cwjiof 当前离线   回复时引用此帖
旧 09-11-01, 18:42 第 11 帖
gfreezy
 
 
 
注册会员  
  注册日期: Nov 2009
  帖子: 2
  精华: 0
 

忙活了一个下午
  gfreezy 当前离线   回复时引用此帖
旧 09-11-17, 17:43 第 12 帖
leitian
 
 
 
注册会员  
  注册日期: Jul 2004
  帖子: 23
  精华: 0
 

想不到搜索到一个好东西
  leitian 当前离线   回复时引用此帖
旧 09-11-17, 22:05 第 13 帖
carbonjiao
 
carbonjiao 的头像
 
 
注册会员  
  注册日期: Mar 2004
  我的住址: 广州番禺
  帖子: 793
  精华: 4
 

支持

不过我一直用 lighttp + php + mysql

留个脚印,方便以后查阅







__________________
Archlive <http://archlive.googlecode.com>
Archlive-pkg <http://archlive-pkg.googlecode.com>
Acer TravelMate 3282WXMI
Asus A8Tc
[url=http://tool.115.com/ip][img]http://tool.115.com/live/myip[/img][/url]
  carbonjiao 当前离线   回复时引用此帖
旧 09-11-18, 14:11 第 14 帖
axlrose
 
 
 
注册会员  
  注册日期: Feb 2006
  我的住址: 四川成都
  帖子: 1,274
  精华: 2
 

08的精华呀,没注意到
我平时也用的是lighttpd, 看到网上到处都说nginx牛B
看了网上的一个BLOG,把lighttpd的 epoll模式打开,速度一样很快的
平时用httpd的目的就为了arch pkgs共享用,最近用来做gitweb来用
找个时间试一下nginx看看,看了一下配置,好像挺容易上手的







__________________
gentoo archlinux debian freebsd amd3600+ T61
GunsNRose

我的百度BLOG: http://hi.baidu.com/3444542
  axlrose 当前离线   回复时引用此帖
旧 09-11-18, 14:19 第 15 帖
sanyork 帅哥
 
sanyork 的头像
 
 
注册会员  
  注册日期: Sep 2004
  我的住址: 杭州
  帖子: 124
  精华: 0
 

服务器的东西,还是用红帽或者大便的来的好一点吧







__________________
CPU: Intel Pentium IV 2.8G HT
内存: 1G DDR2
主板: Intel 915
显卡: Intel Integration
硬盘: 西部数据 80G 8M Cache
显示器: DELL 17" LCD
  sanyork 当前离线   回复时引用此帖
发表新主题 回复


主题工具

发帖规则
您 [不可以] 发表新主题
您 [不可以] 回复主题
您 [不可以] 上传附件
您 [不可以] 编辑您的帖子

已 [启用] BB 代码
已 [启用] 表情符号
已 [启用] IMG 代码
已 [禁用] HTML 代码
[论坛跳转…]


所有时间均为[北京时间]。现在的时间是 03:23


Powered by vBulletin 版本 3.6.8
版权所有 ©2000 - 2010, Jelsoft Enterprises Ltd.
官方中文技术支持: vBulletin 中文
版权所有 ©2002 - 2009, LinuxSir.Org