php-fpm 以及 nginx相关配置

最终处理方案

apt-get php5-cgi php5-fpm spawn-fcgi

修改相关配置

vi /etc/rc.local

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u user -f /usr/bin/php-cgi


1.配置php-fpm

cp php/etc/php-fpm.conf.default php/etc/php-fpm.conf
vi php/etc/php-fpm.conf

修改用户,组,监听IP以及端口

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = enderiose
group = enderiose

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000
2.制作fpm启动服务
复制下面的代码,vi /etc/init.d/php-fpm,保存 
修改可执行权限  chmod +x /etc/init.d/php-fpm 
启动   /etc/init.d/php-fpm start 
停止   /etc/init.d/php-fpm stop 
重启   /etc/init.d/php-fpm restart
    #!/bin/bash    
    # php-fpm Startup script for php-fpm, a FastCGI implementation    
    # this script was created by tony at 2010.07.21, based on jackbillow's nginx script.    
    # it is v.0.0.1 version.    
    # if you find any errors on this scripts,please contact tony.    
    # by sending mail to tonytzhou at gmail dot com.    
    #    
    # chkconfig: - 85 15    
    # description: php-fpm is an alternative FastCGI implementation, with some additional features useful for sites of any size, especially busier sites.    
    #    
    # processname: phpfpm    
    # pidfile: /usr/local/var/run/phpfpm.pid    
    # config: /usr/local/etc/phpfpm.conf    
        
    phpfpm=/home/lnmp/php/sbin/php-fpm    
    config=/home/lnmp/php/lib/php.ini    
    pid=/home/lnmp/php/run/php-fpm.pid    
        
    RETVAL=0    
    prog="phpfpm"    
        
    # Source function library.    
    . /etc/rc.d/init.d/functions    
        
    # Source networking configuration.    
    . /etc/sysconfig/network    
        
    # Check that networking is up.    
    [ ${NETWORKING} = "no" ] && exit 0    
        
    [ -x $phpfpm ] || exit 0    
        
    # Start phpfpm daemons functions.    
    start() {    
        
    if [ -e $pid ];then    
       echo "phpfpm is already running...."    
       exit 1    
    fi    
        
       echo -n $"Starting $prog: "    
       daemon $phpfpm -c ${config}    
       RETVAL=$?    
       echo    
       [ $RETVAL = 0 ] && touch /var/lock/subsys/phpfpm    
       return $RETVAL    
        
    }    
        
    # Stop phpfpm daemons functions.    
    stop() {    
            echo -n $"Stopping $prog: "    
            killproc $phpfpm    
            RETVAL=$?    
            echo    
            [ $RETVAL = 0 ] && rm -f /var/lock/subsys/phpfpm /var/run/phpfpm.pid    
    }    
        
    # reload phpfpm service functions.    
    reload() {    
        
        echo -n $"Reloading $prog: "    
        #kill -HUP `cat ${pid}`    
        killproc $phpfpm -HUP    
        RETVAL=$?    
        echo    
        
    }    
        
    # See how we were called.    
    case "$1" in    
    start)    
            start    
            ;;    
        
    stop)    
            stop    
            ;;    
        
    reload)    
            reload    
            ;;    
        
    restart)    
            stop    
            start    
            ;;    
        
    status)    
            status $prog    
            RETVAL=$?    
            ;;    
    *)    
            echo $"Usage: $prog {start|stop|restart|reload|status|help}"    
            exit 1    
    esac    
        
    exit $RETVAL  

3.配置nginx

    #user  nobody;    
    user enderiose enderiose;    
    worker_processes  4;    
    #error_log  logs/error.log;    
    #error_log  logs/error.log  notice;    
    #error_log  logs/error.log  info;    
    pid        logs/nginx.pid;    
    # 指定文件描述符数量    
    worker_rlimit_nofile 51200;    
    events {    
        # 使用网络I/O模型,linux推荐使用epoll, FressBSD推荐私用kqueue    
        use epoll;    
        # 允许链接数    
        worker_connections  51200;    
    }    
    http {    
        include       mime.types;    
        default_type  application/octet-stream;    
            
        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  logs/access.log  main;    
            
        #autoindex off;    
        # 设置字符集,如果多种字符集,不要设置    
        #charset utf-8;    
            
        sendfile        on;    
        keepalive_timeout  65;    
            
        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    
        gzip on;    
        gzip_min_length 1k;    
        gzip_buffers 4 16k;    
        gzip_http_version 1.1;    
        gzip_comp_level 6;    
        gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;    
        gzip_vary on;    
            
        server {    
            listen 80;    
            server_name localhost;    
            index index.html index.htm index.php;    
            root web-root;    
                
            # 图片缓存    
            location ~* \.(?:ico|gif|jpe?g|png|bmp|swf)$ {    
                    # Some basic cache-control for static files to be sent to the browser    
                    expires max;    
                    add_header Pragma public;    
                    add_header Cache-Control "public, must-revalidate, proxy-revalidate";    
            }    
        
            # 静态资源缓存    
            location ~.*\.(js|css)?$    
            {    
                expires 1h;    
            }    
                
            error_page   500 502 503 504  /50x.html;    
            location = /50x.html {    
                root   html;    
            }    
                
            #    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000    
            #    
            location ~ \.php$ {    
                root web-root;    
                fastcgi_pass 127.0.0.1:9000; # fpm监听的端口和ip    
                fastcgi_index  index.php;    
                fastcgi_param  SCRIPT_FILENAME  web-root$fastcgi_script_name;    
                include        fastcgi_params;    
            }    
        
        }    
           
    } 
wq这个nginx.conf

启动nginx

nginx/bin 或者nginx/sbin
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值