Nginx 连接php

    安装php的依赖包

yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-
devel -y

    编译安装php

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-
bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local
--with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-
dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --
with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --
enable-xml --enable-fpm --with-libdir=lib64
make
make install
配置 php    
    cp php.ini-production /usr/local/php/etc/php.ini
    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
启动 php-fpm
    /usr/local/php/sbin/php-fpm
通过端口判断是 PHP 否启动
    # netstat -lnt | grep 9000
    tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN

Nginx配置

server {
    listen 80;
    server_name test.jwh5566.com;
    access_log /data/logs/nginx/test.ttlsa.com.access.log main;
    index index.php index.html index.html;
    root /www/html/test.jwh5566.com;
    location /
        {
        try_files $uri $uri/ /index.php?$args; #根据uri依次找文件
        }
    location ~ .*\.(php)?$
        {
        expires -1s;
        try_files $uri =404;#找不到返回404
        fastcgi_split_path_info ^(.+\.php)(/.+)$;#将url切分获取fastcgi_params的变量
        include fastcgi_params;#包含变量
        fastcgi_param PATH_INFO $fastcgi_path_info;#自定义变量
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #脚本文件请求的路径
        fastcgi_pass 127.0.0.1:9000;
        }
 }
 注:将 fastcgi_pass 127.0.0.1:9000;改成 fastcgi_pass unix:/dev/shm/phpfpm.sock;速度更快
 使用sock连接方式
    touch /dev/shm/phpfpm.sock
    chown nobody:nobody /dev/shm/phpfpm.sock
    chmod 666 /dev/shm/phpfpm.sock
    #修改php-fpm配置文件
    listen = /dev/shm/phpfpm.sock
    重启php-fpm和nginx

nginx配置虚拟主机

    

server{
    server_name a.ttlsa.com;
    listen 80;
    root /www/html/a.ttlsa.com;
    access_log /www/html/a.ttlsa.com/logs/a.ttlsa.com-access.log main;
    location /
    {
    }
}
server{
    server_name b.ttlsa.com;
    listen 80;
    root /www/html/b.ttlsa.com;
    access_log /www/html/b.ttlsa.com/logs/b.ttlsa.com-access.log main;
    location /
    {
    }
}