ubuntu10.04配备 nginx + php-fpm 模式
ubuntu10.04配置 nginx + php-fpm 模式
ppa安装php-fpm
安装工具包
$ sudo apt-get install python-software-properties
添加ppa源
$ sudo add-apt-repository ppa:yola/php5
安装php5-fpm
sudo apt-get updatesudo apt-get install php5-fpm
其它必要的软件安装接
sudo apt-get install nginx
配置php-fpm
php-fpm的解析器是C/S结构,它的配置文件位于:
(1)/etc/php5/fpm/php-fpm.conf
(2)/etc/php5/fpm/pool.d/
一般没什么严格的配置的要求,或者说这块我还没有具体的研究每个配置参数的意义
我采用了tcp模式与fastcgi进程进行连接,因此我修改了tcp监听的地址和端口,修改了一下监视目录的名称,这里不做具体详细解释了,大家可以参考官方文档根据自己的需求进行配置
重启php5-fpm
配置nginx
前言
nginx本身并不会对php语言进行解析,这个区别于apache(apache有在带的mod_php模块进行php解析).nginx是通过fastcgi将客户端的php请求交给后台的php5-fpm进程管理器,php5-fpm具有解析php的功能,具体可以参考我之前的一篇博客mod_php对比mod_fastcgi
nginx的主配置文件
文件位置:/etc/nginx/nginx.conf,我的配置参数如下:
user www-data;#主动开启cpu多核功能worker_processes 2;worker_cpu_affinity 01 10;#指定nginx进程可以打开的最大文件描述符数量worker_rlimit_nofile 65535;pid /var/run/nginx.pid;events { #使用epoll的I/O模型 use epoll; #工作单进程的并发连接数,总体并发连接数 = worker_connections * worker_processes worker_connections 2048; #multi_accept在Nginx接到一个新连接通知后调用accept()来接受尽量多的连接 multi_accept on;}http { include /etc/nginx/mime.types; default_type application/octet-stream; charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 2k; large_client_header_buffers 4 4k; #通过nginx上传文件的大小 client_max_body_size 8m; #$remote_addr:记录ip地址;$remote_user:记录远程客户端用户名称;$request:请求的url和http协议;$status:用于记录请求状态;$body_bytes_sent:用于记录发送给客户端文件主体内容的大小;$http_referer:跳转链接;$http_x_forwarded_for:客户的真实ip地址 log_format main '$server_name$remote_addr$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent""$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; sendfile on; tcp_nopush on; #keepalive的超时时间 keepalive_timeout 60; open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 30s; tcp_nodelay on; gzip on; include /etc/nginx/conf.d/*.conf;}
nginx虚拟主机配置文件
upstream haolianxi_php { server 127.0.0.1:9444;}server { listen 192.168.1.137:7777; access_log /var/log/nginx/haolianxi/haolianxi.access.log main; error_log /var/log/nginx/haolianxi/haolianxi.error.log; #通用匹配 location / { root /srv/www/php/; autoindex on; autoindex_exact_size off; autoindex_localtime on; access_log /var/log/nginx/haolianxi/location.default.access.log main; error_log /var/log/nginx/haolianxi/location.default.error.log; allow 192.168.1.0/24; deny all; } #正则表达式匹配 #proxy the php scripts to php-fpm location ~ \.php$ { root /srv/www/php/; include /etc/nginx/fastcgi_params; fastcgi_pass haolianxi_php; # The upstream determined above fastcgi_index index.php; } #php-fpm status monitor location = /phpfpm_status { fastcgi_pass 127.0.0.1:9444; fastcgi_index index.php; include /etc/nginx/fastcgi_params; allow 192.168.1.127; allow 127.0.0.1; deny all; } ## Compression # src: http://www.ruby-forum.com/topic/141251 # src: http://wiki.brightbox.co.uk/docs:nginx gzip on; gzip_http_version 1.0; gzip_comp_level 2; gzip_proxied any; gzip_min_length 1100; gzip_buffers 16 8k; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; # Some version of IE 6 don't handle compression well on some mime-types, so just disable for them gzip_disable "MSIE [1-6].(?!.*SV1)"; # Set a vary header so downstream proxies don't send cached gzipped content to IE6 gzip_vary on; ## /Compression}
注意:
include /etc/nginx/fastcgi_params中一个参数设置需要修改,修改如下:
fastcgi_param SCRIPT_NAME $document_root$fastcgi_script_name;
因为脚本的名称不加上$document_root,php5-fpm是无法找到需要执行的php脚本的绝对路径的
重启nginx
sudo /etc/init.d/nginx restart
测试fastcgi_finish_request()函数
<?phpecho "OK";fastcgi_finish_request(); /* 响应完成, 关闭连接 */sleep(5);file_put_contents("/tmp/fastcgi.log", "hello",FILE_APPEND);sleep(5);file_put_contents("/tmp/fastcgi.log", "world",FILE_APPEND);?>
说明:
用最大的白话说,fastcgi_finish_request()可以提前关闭和客户端的连接,把需要返回的数据返回给客户端,但是函数之后的分支业务逻辑还是继续在后台运行!
php5-fpm日志按天分割脚本
#!/bin/bash - #1.php5-fpm日志存放路径php5_fpm_logs_path="/var/log/php5-fpm/"category_array=("access" "error")#2.php5-fpm日志名后缀postfix=`date -d '-1 days' +%Y%m%d`".log"#3.php5-fpm日志切割for category in ${category_array[*]}do if [ -e $php5_fpm_logs_path/php5-fpm.$category.log ] then mv $php5_fpm_logs_path/php5-fpm.$category.log \ $php5_fpm_logs_path/php5-fpm.$category.$postfix fidone#4.查找php5-fpm进程号,让其产生新的日志文件php5fpm_pid=`ps -aux |grep -E 'php-fpm: master process'|grep -v 'grep'|awk '{print $2}'`#USR1:Reopen log files,刷新nginx日志文件kill -USR1 $php5fpm_pid

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PHP主要是過程式編程,但也支持面向對象編程(OOP);Python支持多種範式,包括OOP、函數式和過程式編程。 PHP適合web開發,Python適用於多種應用,如數據分析和機器學習。

PHP適合網頁開發和快速原型開發,Python適用於數據科學和機器學習。 1.PHP用於動態網頁開發,語法簡單,適合快速開發。 2.Python語法簡潔,適用於多領域,庫生態系統強大。

PHP起源於1994年,由RasmusLerdorf開發,最初用於跟踪網站訪問者,逐漸演變為服務器端腳本語言,廣泛應用於網頁開發。 Python由GuidovanRossum於1980年代末開發,1991年首次發布,強調代碼可讀性和簡潔性,適用於科學計算、數據分析等領域。

PHP的核心優勢包括易於學習、強大的web開發支持、豐富的庫和框架、高性能和可擴展性、跨平台兼容性以及成本效益高。 1)易於學習和使用,適合初學者;2)與web服務器集成好,支持多種數據庫;3)擁有如Laravel等強大框架;4)通過優化可實現高性能;5)支持多種操作系統;6)開源,降低開發成本。

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

Docker 容器啟動步驟:拉取容器鏡像:運行 "docker pull [鏡像名稱]"。創建容器:使用 "docker create [選項] [鏡像名稱] [命令和參數]"。啟動容器:執行 "docker start [容器名稱或 ID]"。檢查容器狀態:通過 "docker ps" 驗證容器是否正在運行。

可以通過以下步驟查詢 Docker 容器名稱:列出所有容器(docker ps)。篩選容器列表(使用 grep 命令)。獲取容器名稱(位於 "NAMES" 列中)。

PHP適用於Web開發和內容管理系統,Python適合數據科學、機器學習和自動化腳本。 1.PHP在構建快速、可擴展的網站和應用程序方面表現出色,常用於WordPress等CMS。 2.Python在數據科學和機器學習領域表現卓越,擁有豐富的庫如NumPy和TensorFlow。
