技术文章

安装配置nginx +php-fpm

  1. nginx安装成功
    突然想研究一下,nginx+php的工作方式,搞近一天时间,终于可以运行了,记录下来,
    参考:1,http://blog.163.com/koumm@126/blog/static/9540383720096307529267/
          2,http://www.inginx.com/nginx-manual-download/
          3,http://wiki.nginx.org/NginxChs
    
    系统:ubuntu /php5.3.18/nginx 1.0.15
    首先安装:nginx
    安装gcc/prce/
      apt-get install gcc
      apt-get install pcre-dev
    
      apt-get install libpcre3-dev
       ./configure --profix=/usr/local/nginx
       make
      make install
    
    2,安装php
    cd /home/datasoft/php-5.3.18/
      380  ls
    
      383  ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php/etc
    --enable-fastcgi //关键的两行
    --enable-fpm // fpm管理器
    --enable-force-cgi-redirect
      384  make
      385  make install
    
    注:如果安装php, make   时 有xxx.lo错误时用,make clean之后安装成功。 如果编译环境相同的机器直接COPY就可以然后
    echo '/usr/local/php/lib' >>/etc/ld.so.conf;ldconfig 就OK了
    问题2,php 解析不了,访问时下载,nginx.conf   默认loction配置问题
    建立fpm运行用户
    groupadd nobody;
    useradd nobody nobody;
    起运fpm
    /usr/local/php5/sbin/php-fpm 
    查看是否起动成功
    netstat -npl | grep 9000
    root@ubuntu:/# netstat -npl | grep 9000
    tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      907/php-fpm.conf)
    起动成功
    
    配置nginx.conf
    
    user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    pid        logs/nginx.pid;#打开这里,kill -HUP `cat /usr/local/nginx/logs/nginx.pid`使用
    
    events {
            use epoll; #以epoll的工作方式
        worker_connections  1024;
    }
    
    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;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    server { 
            listen       80; 
            server_name  localhost; 
    
            #charset koi8-r; 
    
            #access_log  logs/host.access.log  main; 
    
           # location / {    //一定要注掉这部分,否则会不解析PHP文件,而会下载 了 
            #    root   html; 
            #    index  index.html index.htm; 
            #} 
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ \.php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #开启以下部分以便nginx以fastcgi解析php
            location ~ \.php$ {
                root           /usr/local/nginx/html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                include        fastcgi_params;
            }
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /\.ht {
            #    deny  all;
            #}
        }
    
    重起nginx
    kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
    或者 nginx -t查看nginx.conf是否配置有错误
    在IE或者其他浏览器查看,配置成功!
    备份一个有用的linux管理工具:webmin
  2. 附vhost配置文件一份
  3. [well]                                                                                                                                                                                                                                              nginx.confuser nobody;
    worker_processes 8;
    worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
    worker_rlimit_nofile 65536;error_log /dev/null;
    #error_log logs/error.log debug;

    events {
    use epoll;
    worker_connections 65536;
    }
    http {
    include mime.types;
    default_type application/octet-stream;

    sendfile on;

    keepalive_timeout 30;

    log_format access ‘$host $remote_addr $upstream_addr $upstream_status [$time_local] “$request” ‘
    ‘$status $body_bytes_sent $request_time “$http_referer” “$http_user_agent”‘;

    access_log logs/access.log access;

    client_body_buffer_size 512k;

    proxy_connect_timeout 15;
    proxy_read_timeout 60;
    proxy_send_timeout 15;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;

    ssi on;
    ssi_silent_errors on;
    ssi_types text/xml;

    # gzip on;
    # gzip_min_length 1k;
    # gzip_buffers 4 16k;

    include vhosts/*.conf;     [/well]      [well]                                                                                                                                                                                                                                     server {
    listen 80;
    server_name xx.ebankie.com;

    root /data/shipei/;
    index index.htm;

    location ~ \.php {
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    fastcgi_buffer_size 32k;
    fastcgi_buffers 8 32k;

    include fastcgi.conf;
    }

    location ^~ /a/ {
    rewrite ^/a/([^/]+)/? /index.php?site=$1 last;
    rewrite ^/a/([^/]+)/? /index.php?site=$1 last;
    }

     

    }[/well]

Leave a Reply

Free Web Hosting