查看: 6741|回复: 0
打印 上一主题 下一主题

Nginx 0.6.31 + PHP 5.2.6(FastCGI)搭建Web服务器(二)

[复制链接]
跳转到指定楼层
1#
发表于 2008-8-29 21:27:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
9、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启25个进程),用户为www:


ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start

  注:/usr/local/webserver/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。


--------------------------------------------------------------------------------

  三、安装Nginx 0.6.31
  1、安装Nginx所需的pcre库:

tar zxvf pcre-7.7.tar.gz
cd pcre-7.7/
./configure
make && make install
cd ../


  2、安装Nginx

tar zxvf nginx-0.6.31.tar.gz
cd nginx-0.6.31/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../


  3、创建Nginx日志目录

mkdir -p /data1/logs
chmod +w /data1/logs
chown -R www:www /data1/logs


  4、创建Nginx配置文件
  ①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:

rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf

  输入以下内容:

引用
user  www www;

worker_processes 8;

error_log  /data1/logs/nginx_error.log  crit;

pid        /usr/local/webserver/nginx/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       mime.types;
     default_type  application/octet-stream;

     charset  utf-8;
     
     server_names_hash_bucket_size 128;
     
     sendfile on;
     tcp_nopush     on;

     keepalive_timeout 60;

     tcp_nodelay on;

     fastcgi_connect_timeout 60;
     fastcgi_send_timeout 180;
     fastcgi_read_timeout 180;
     fastcgi_buffer_size 128k;
     fastcgi_buffers 4 128k;
     fastcgi_busy_buffers_size 128k;
     fastcgi_temp_file_write_size 128k;
     fastcgi_temp_path /dev/shm;

     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  blog.s135.com;
             index index.html index.htm index.php;
             root  /data0/htdocs/blog;

             if (-d $request_filename)
             {
                    rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
             }
                           
             location ~ .*\.php?$
             {
                  include fcgi.conf;      
                  #fastcgi_pass  unix:/tmp/php-cgi.sock;
                  fastcgi_pass  127.0.0.1:9000;
                  fastcgi_index index.php;
             }

             log_format  access  '$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  access;
     }

     server
     {
             listen       80;
             server_name  www.s135.com;
             index index.html index.htm index.php;
             root  /data0/htdocs/www;

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

             location ~ .*\.php?$
             {
                  include fcgi.conf;
                  #fastcgi_pass  unix:/tmp/php-cgi.sock;
                  fastcgi_pass  127.0.0.1:9000;
                  fastcgi_index index.php;
             }

             log_format  wwwlogs  '$remote_addr - $remote_user [$time_local] "$request" '
                                   '$status $body_bytes_sent "$http_referer" '
                                   '"$http_user_agent" $http_x_forwarded_for';
             access_log  /data1/logs/wwwlogs.log  wwwlogs;
     }

     server
     {
             listen  80;
             server_name  status.blog.s135.com;

             location / {
                  stub_status on;
                  access_log   off;
             }
     }
}


  ②、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:

vi /usr/local/webserver/nginx/conf/fcgi.conf

  输入以下内容:

引用
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param  REDIRECT_STATUS    200;


  5、启动Nginx

ulimit -SHn 51200
/usr/local/webserver/nginx/sbin/nginx


--------------------------------------------------------------------------------

  四、配置开机自动启动Nginx + PHP

vi /etc/rc.local

  在末尾增加以下内容:

引用
ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx


--------------------------------------------------------------------------------

  五、优化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


--------------------------------------------------------------------------------

  六、在不停止Nginx服务的情况下平滑变更Nginx配置
  (1)、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:

/usr/local/webserver/nginx/sbin/nginx -t

  如果屏幕显示以下两行信息,说明配置文件正确:
  the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
  the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully

  (2)、这时,输入以下命令查看Nginx主进程号:

ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'

  屏幕显示的即为Nginx主进程号,例如:
  6302
  这时,执行以下命令即可使修改过的Nginx配置文件生效:

kill -HUP 6302

  或者无需这么麻烦,找到Nginx的Pid文件:

kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`


--------------------------------------------------------------------------------

  本文若有小的修改,会第一时间在以下网址发布:
  http://blog.s135.com/read.php/351.htm
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表