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 update
sudo 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的功能
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;
}
日志格式之间是用不可打印符号进行分隔的,ctrl+v && ctrl+a
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()函数
复制代码 代码如下:
echo "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
fi
done
#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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

If you have successfully downloaded the installation file of Baidu Netdisk, but cannot install it normally, it may be that there is an error in the integrity of the software file or there is a problem with the residual files and registry entries. Let this site take care of it for users. Let’s introduce the analysis of the problem that Baidu Netdisk is successfully downloaded but cannot be installed. Analysis of the problem that Baidu Netdisk downloaded successfully but could not be installed 1. Check the integrity of the installation file: Make sure that the downloaded installation file is complete and not damaged. You can download it again, or try to download the installation file from another trusted source. 2. Turn off anti-virus software and firewall: Some anti-virus software or firewall programs may prevent the installation program from running properly. Try disabling or exiting the anti-virus software and firewall, then re-run the installation

Installing Android applications on Linux has always been a concern for many users. Especially for Linux users who like to use Android applications, it is very important to master how to install Android applications on Linux systems. Although running Android applications directly on Linux is not as simple as on the Android platform, by using emulators or third-party tools, we can still happily enjoy Android applications on Linux. The following will introduce how to install Android applications on Linux systems.

Understanding Linux Bashrc: Function, Configuration and Usage In Linux systems, Bashrc (BourneAgainShellruncommands) is a very important configuration file, which contains various commands and settings that are automatically run when the system starts. The Bashrc file is usually located in the user's home directory and is a hidden file. Its function is to customize the Bashshell environment for the user. 1. Bashrc function setting environment

Even answering calls in Do Not Disturb mode can be a very annoying experience. As the name suggests, Do Not Disturb mode turns off all incoming call notifications and alerts from emails, messages, etc. You can follow these solution sets to fix it. Fix 1 – Enable Focus Mode Enable focus mode on your phone. Step 1 – Swipe down from the top to access Control Center. Step 2 – Next, enable “Focus Mode” on your phone. Focus Mode enables Do Not Disturb mode on your phone. It won't cause any incoming call alerts to appear on your phone. Fix 2 – Change Focus Mode Settings If there are some issues in the focus mode settings, you should fix them. Step 1 – Open your iPhone settings window. Step 2 – Next, turn on the Focus mode settings

If you have used Docker, you must understand daemons, containers, and their functions. A daemon is a service that runs in the background when a container is already in use in any system. Podman is a free management tool for managing and creating containers without relying on any daemon such as Docker. Therefore, it has advantages in managing containers without the need for long-term backend services. Additionally, Podman does not require root-level permissions to be used. This guide discusses in detail how to install Podman on Ubuntu24. To update the system, we first need to update the system and open the Terminal shell of Ubuntu24. During both installation and upgrade processes, we need to use the command line. a simple

While studying in high school, some students take very clear and accurate notes, taking more notes than others in the same class. For some, note-taking is a hobby, while for others, it is a necessity when they easily forget small information about anything important. Microsoft's NTFS application is particularly useful for students who wish to save important notes beyond regular lectures. In this article, we will describe the installation of Ubuntu applications on Ubuntu24. Updating the Ubuntu System Before installing the Ubuntu installer, on Ubuntu24 we need to ensure that the newly configured system has been updated. We can use the most famous "a" in Ubuntu system

Detailed steps to install Go language on Win7 computer Go (also known as Golang) is an open source programming language developed by Google. It is simple, efficient and has excellent concurrency performance. It is suitable for the development of cloud services, network applications and back-end systems. . Installing the Go language on a Win7 computer allows you to quickly get started with the language and start writing Go programs. The following will introduce in detail the steps to install the Go language on a Win7 computer, and attach specific code examples. Step 1: Download the Go language installation package and visit the Go official website

Title: A complete guide to installing FTPS service under Linux system In Linux system, setting up an FTP server is a common requirement. However, in order to enhance the security of data transmission, we can choose to install the FTPS service, which adds SSL/TLS encryption function based on the FTP protocol. Through the FTPS service, we can upload and download files while ensuring the security of data transmission. This article will provide a detailed guide for installing FTPS service under Linux system and provide specific instructions.
