+ -
当前位置:首页 → 问答吧 → [参考]搭建Nginx 0.5.35 + php 5.2.5 (ArchLinux)

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

时间:2008-04-06

来源:互联网

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

代码:
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/

作者: store88   发布时间: 2008-04-06

这么有意义的帖子,怎能不回?

作者: cwjiof   发布时间: 2008-04-06

不错不错,支持

作者: jarryson   发布时间: 2008-04-07

不错,正需要

作者: gogonkt   发布时间: 2008-04-13

不懂为什么要通过安装 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;

作者: lwkyy   发布时间: 2009-10-11

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

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

作者: jqxl0205   发布时间: 2009-10-11

我按这配置没办法成功,getgrnam("nginx")问题没办法解决,看了下张宴的配置过程,装nginx的user改用www后(建立了www用户httproot目录也给了www),nginx能启动起来了,测试个HTML文件也没问题,但测试php文件时就不行了,提示找不到404,郁闷。

作者: lwkyy   发布时间: 2009-10-11

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

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   发布时间: 2009-10-13

默认php软件包不包含FastCGI,所以要安装下
sudo pacman -S php php-cgi
这样就可以了

作者: gfreezy   发布时间: 2009-11-01

顶楼写文的时候,确实是包含 FastCGI 的,但后来 php 和 php-cgi 被分成两个包了,原因当然是 KISS,呵呵。

作者: cwjiof   发布时间: 2009-11-01

忙活了一个下午

作者: gfreezy   发布时间: 2009-11-01

想不到搜索到一个好东西

作者: leitian   发布时间: 2009-11-17

支持

不过我一直用 lighttp + php + mysql

留个脚印,方便以后查阅

作者: carbonjiao   发布时间: 2009-11-18

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

作者: axlrose   发布时间: 2009-11-18

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

作者: sanyork   发布时间: 2009-11-18

Zend Optimizer这个是不是必须的?
我只在本机上使用,连接数非常有限。

作者: zswlb9999   发布时间: 2009-11-18

在nginx.conf的文件中常有:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


其中的$document_root是在何处定义的?

我将$document_root改为我的PHP文件所在目录, 如改为/data 即
/data/$fastcgi_script_name;
就正常了。

作者: zswlb9999   发布时间: 2009-12-02

热门下载

更多