search
HomeOperation and MaintenanceNginxHow to solve the error when nginx calls php-fpm

After installing nginx and php-5.5, and configuring nginx to call php, start php-fpm.

Use the following command

Copy the code The code is as follows:

/usr/local/php/sbin/php-fpm

That’s it started.

Create a PHP detection script index.php in the nginx directory

The result is that when opening http://localhost/index.php

The tragic discovery is that it cannot be opened. . Check the log file and see the reason for the error

Copy code The code is as follows:

2013/07/01 22:34:26 [error] 3214#0: *64 fastcgi sent in stderr: "primary script unknown" while reading response header from upstream, client: 192.168.168.19, server: localhost, request: "get /index.php http/1.1", upstream: "fastcgi://127.0.0.1:9000 ", host: "192.168.168.140"

Check the port. Seeing that the 9000 port of php-fpm has been opened, it means that there is no problem with php-fpm. The problem lies with nginx. Maybe there is something wrong with my configuration file.

Find the part where nginx loads the php configuration. Also refer to the nginx configuration file online.

There is a calling script path on line 69

Copy the code The code is as follows:

fastcgi_param script_filename /scripts$fastcgi_script_name;

I put Just change the path to the following.

Copy code The code is as follows:

fastcgi_param script_filename $document_root$fastcgi_script_name;

http://localhost/index.php

The version information of php can appear.
You can also refer to the configuration method below

php-fpm no longer needs to rely on other fastcgi launchers, such as lighttpd's spawn-fcgi.
php-fpm is very convenient to use, the configuration is in the php-fpm.ini file
Startup and restart can be done from php/sbin/php-fpm
More conveniently is modification After php.ini, you can directly use php-fpm reload to load it. You can complete the modification and loading of php.ini without killing the process.
The results show that using php-fpm can significantly improve the performance of php
php-fpm The CPU recycling speed of the controlled process is relatively slow. The memory allocation is very even.
The CPU of the process controlled by spawn-cgi drops very quickly. The memory allocation is relatively uneven.
There are many processes that seem to be unallocated. , while others occupy very high amounts.
It may be caused by the uneven distribution of process tasks. This also leads to a decrease in the overall response speed
And php-fpm's reasonable allocation leads to an improvement in the overall response and the average task
Using php-fpm requires patching the php source code, and then recompiling php

1. Download php-fpm
wget http://cn.php.net/ get/php-5.2.8.tar.gz/from/www.php.net/mirror
wget http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5 .10.diff.gz
In the same directory as php-5.2.9
gzip -cd php-5.2.8-fpm-0.5.10.diff.gz | patch -d php-5.2.9 - After the p1
patch is applied, the following parameters are added when compiling php:
–enable-fpm activates fastcgi mode fpm support
–with-fpm-conf php-fpm configuration file (default Is prefix/etc/php-fpm.conf)
–with-fpm-log php-fpm’s log file (the default is prefix/logs/php-fpm.log)
–with-fpm-pid php- fpm's pid file (default is prefix/logs/php-fpm.pid)
./configure --prefix=/ebs/php \
--with-config-file-path=/ebs/php/ etc \
--enable-fastcgi \
--enable-fpm \
--others
Note: --enable-fastcgi \ needs to be in front of --enable-fpm \, otherwise, fpm cannot be compiled.

2. After compiling php, modify the configuration file
vi /ebs/php/etc/php-fpm.conf
You need to pay attention to the following configurations
127.0.0.1:9000
This represents the IP address and port that PHP's fastcgi process listens to
nobody
< ;value name="group">nobody
Indicates which user and user group the PHP fastcgi process runs as. By default, this line is commented out and needs to be turned on
0
Whether to display php error messages
5
Maximum number of child processes
Run php-fpm :
php-fpm uses a program to control the fastcgi process. This file is in $prefix/sbin/php-fpm
/usr/local/php/sbin/php-fpm
The program has the following parameters:
start Start the fastcgi process of php
stop Forcefully terminate the fastcgi process of php
quit Smoothly terminate the fastcgi process of php
restart Restart the fastcgi process of php
reload Reload the php.ini of php ##logrotate Re-enable the log file
In other words, after modifying php.ini, we can use
/usr/local/php/sbin/php-fpm reload
In this way, it remains in While php's fastcgi process continues to run, php.ini is reloaded.

Copy code The code is as follows:

user www www;
worker_processes 10;
error_log logs/error.log notice;
pid logs/nginx.pid;
#specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
   use epoll;
   worker_connections 51200;
}
http
{
   include mime.types;
   default_type application/octet-stream;
   charset gb2312;
   server_names_hash_bucket_size 128;
   #sendfile on;
   #tcp_nopush on;
   keepalive_timeout 60;
   tcp_nodelay on;
   gzip on;
   gzip_min_length 1k;
   gzip_buffers 4 8k;
   gzip_http_version 1.1;
   gzip_types text/plain application/x-javascript text/css text/html application/xml;
   {
   listen 80;
   server_name 192.168.1.2;
   index index.html index.htm index.php;
   root /ebs/www;
   if (-d $request_filename)
   {
   rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
   }
   location ~ .*\.php?$
   {
   include fcgi.conf

   fastcgi_pass 127.0.0.1:9000;
   fastcgi_index index.php;
   }
   log_format access '$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 access;
   }
}

新建配置文件

复制代码 代码如下:

/usr/local/nginx/conf/fcgi.conf

注:nginx自带了一个配置文件,/usr/local/nginx/conf/fastcgi_params,该配置文件缺少粗体字体的部分,会造成访问php文件时报404错误。

复制代码 代码如下:

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 only, required if php was built with --enable-force-cgi-redirect
#fastcgi_param redirect_status 200;

四 配置xcache
1、安装xcache模块
wgethttp://xcache.lighttpd.net/pub/releases/1.2.2/xcache-1.2.2.tar.gz
tar -xvzf xcache-1.2.2.tar.gz
cd xcache-1.2.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache --enable-xcache-optimizer
make
make install
2、计算密码的md5值
echo -n "password"|md5sum
5f4dcc3b5aa765d61d8327deb882cf99
3、配置xcache
;注:zend_extension,用来加载zend的扩展,是绝对路径, extension是相对路径,相对于extension_dir的相对路径,非zend扩展
如果你更改路径以后,一定要apachectl stop后再start,而不要restart。
vi /usr/local/php/etc/php.ini

添加:

复制代码 代码如下:

[xcache-common]
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
[xcache.admin]
; change xcache.admin.user to your preferred login name
xcache.admin.user = "admin"
; change xcache.admin.pass to the md5 fingerprint of your password
; use md5 -s "your_secret_password" to find the fingerprint
xcache.admin.pass = "5f4dcc3b5aa765d61d8327deb882cf99"
[xcache]
; change xcache.size to tune the size of the opcode cache
xcache.size = 24m
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8k
xcache.ttl = 0
xcache.gc_interval = 0
; change xcache.var_size to adjust the size of variable cache
xcache.var_size = 8m
xcache.var_count = 1
xcache.var_slots = 8k
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = off
xcache.readonly_protection = on
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = on
xcache.stat = on
xcache.optimizer = off
[xcache.coverager]
xcache.coverager = on
xcache.coveragedump_directory = ""

5、重启php模块
正常load之后,
在phpinfo显出的信息内
zend这快应该会加上xcache的内容
How to solve the error when nginx calls php-fpm

6、另外两种加速模块:
在我们的测试中,效果都要好于xcache,这3中加速不能同时存在两种,有冲突。
6.1 apc

复制代码 代码如下:

wget http://pecl.php.net/get/apc-3.0.19.tgz
cd apc-3.0.19
/usr/local/php/bin/phpize
./configure --enable-apc --enable-apc-mmap --with-apxs=/ebs/apache/bin/apxs --with-php-config=/ebs/php/bin/php-config
make
make install
6.2 eaccelerator
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.zip
cd eaccelerator-0.9.5.3
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/ebs/php/bin/php-config
make
make install
vi php.ini
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

五、使用nginx对应多台facgi服务器
思路:前端一台nginx,用于做为负载均衡和处理静态页面。利用nginx的upstream模块来将php请求分发到后段的php-fpm服务器上。
后端多台php-fpm的服务器,只起php-fpm服务来处理php。
这样做减少了php-fpm上的nginx服务,相当于少了一层。

The above is the detailed content of How to solve the error when nginx calls php-fpm. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
内存飙升!记一次nginx拦截爬虫内存飙升!记一次nginx拦截爬虫Mar 30, 2023 pm 04:35 PM

本篇文章给大家带来了关于nginx的相关知识,其中主要介绍了nginx拦截爬虫相关的,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

nginx限流模块源码分析nginx限流模块源码分析May 11, 2023 pm 06:16 PM

高并发系统有三把利器:缓存、降级和限流;限流的目的是通过对并发访问/请求进行限速来保护系统,一旦达到限制速率则可以拒绝服务(定向到错误页)、排队等待(秒杀)、降级(返回兜底数据或默认数据);高并发系统常见的限流有:限制总并发数(数据库连接池)、限制瞬时并发数(如nginx的limit_conn模块,用来限制瞬时并发连接数)、限制时间窗口内的平均速率(nginx的limit_req模块,用来限制每秒的平均速率);另外还可以根据网络连接数、网络流量、cpu或内存负载等来限流。1.限流算法最简单粗暴的

nginx php403错误怎么解决nginx php403错误怎么解决Nov 23, 2022 am 09:59 AM

nginx php403错误的解决办法:1、修改文件权限或开启selinux;2、修改php-fpm.conf,加入需要的文件扩展名;3、修改php.ini内容为“cgi.fix_pathinfo = 0”;4、重启php-fpm即可。

nginx+rsync+inotify怎么配置实现负载均衡nginx+rsync+inotify怎么配置实现负载均衡May 11, 2023 pm 03:37 PM

实验环境前端nginx:ip192.168.6.242,对后端的wordpress网站做反向代理实现复杂均衡后端nginx:ip192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库1、在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据下面配置192.168.6.205这台服务器vim/etc/rsyncd.confuid=nginxgid=nginxport=873ho

如何解决跨域?常见解决方案浅析如何解决跨域?常见解决方案浅析Apr 25, 2023 pm 07:57 PM

跨域是开发中经常会遇到的一个场景,也是面试中经常会讨论的一个问题。掌握常见的跨域解决方案及其背后的原理,不仅可以提高我们的开发效率,还能在面试中表现的更加

nginx部署react刷新404怎么办nginx部署react刷新404怎么办Jan 03, 2023 pm 01:41 PM

nginx部署react刷新404的解决办法:1、修改Nginx配置为“server {listen 80;server_name https://www.xxx.com;location / {root xxx;index index.html index.htm;...}”;2、刷新路由,按当前路径去nginx加载页面即可。

Linux系统下如何为Nginx安装多版本PHPLinux系统下如何为Nginx安装多版本PHPMay 11, 2023 pm 07:34 PM

linux版本:64位centos6.4nginx版本:nginx1.8.0php版本:php5.5.28&php5.4.44注意假如php5.5是主版本已经安装在/usr/local/php目录下,那么再安装其他版本的php再指定不同安装目录即可。安装php#wgethttp://cn2.php.net/get/php-5.4.44.tar.gz/from/this/mirror#tarzxvfphp-5.4.44.tar.gz#cdphp-5.4.44#./configure--pr

nginx怎么禁止访问phpnginx怎么禁止访问phpNov 22, 2022 am 09:52 AM

nginx禁止访问php的方法:1、配置nginx,禁止解析指定目录下的指定程序;2、将“location ~^/images/.*\.(php|php5|sh|pl|py)${deny all...}”语句放置在server标签内即可。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use