nginx与php分离搭建
nginx配置
server {
listen 80; 定义端口
server_name www.a.org; 定义域名
location / {
root /www/a.org; 定义php网页面文件路径
index index.php index.html index.htm; 定义能够识别的文件类型
}
location ~ \.php$ {
root /www/a.org; 定义php服务器的网页文件路径
fastcgi_pass 192.168.2.129:9000; 定义php服务器的路径
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
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配置
1、创建nginx用户
2、.修改php-fpm配置文件 /usr/local/php/etc/php-fpm.conf
listen = 172.16.1.2:9000 #监听物理网卡地址,供其它机器调用
user = nginx ##php-fpm以nginx用户运行
group = nginx
重启php-fpm
#service php-fpm restart
关掉两台服务器的防火墙!
五、安装xcache,为php加速:
1、安装
# tar xf xcache-2.0.0.tar.gz
# cd xcache-2.0.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install
安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2、编辑php.ini,整合php和xcache:
首先将xcache提供的样例配置导入php.ini
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d
说明:xcache.ini文件在xcache的源码目录中。
接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
3、重新启动php-fpm
# service php-fpm restart
六、补充说明
如果要在SSL中使用php,需要在php的location中添加此选项:
fastcgi_param HTTPS on;