您好,登錄后才能下訂單哦!
php模塊服務(wù)配置
配置如下
vim /usr/local/nginx_php/etc/php-fpm.conf
[global]
pid = /usr/local/nginx_php/var/run/php-fpm.pid
error_log = /usr/local/nginx_php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm ;運(yùn)行用戶
group = php-fpm ;組
listen.owner = nobody ;監(jiān)聽php-fcgi.sock的用戶
listen.group = nobody
pm = dynamic ;生成進(jìn)程
pm.max_children = 50 可以啟動多少進(jìn)程
pm.start_servers = 10 一開始啟動多少進(jìn)程
pm.min_spare_servers = 5 最少啟動的進(jìn)程數(shù)
pm.max_spare_servers = 25 最多啟動的進(jìn)程數(shù)
pm.max_requests = 500 到達(dá)多少請求后自動結(jié)束進(jìn)程
rlimit_files = 1024 一次請求的最大字節(jié)數(shù)
重新啟動php
/etc/init.d/php-fpm restart
其中php配置文件中的php-fcgi.sock文件所有屬主及屬組是php文件中定義的用戶,
也就是這里的nobody,否則php無法解析php頁面
nginx配置文件如下(按照本次環(huán)境不會出現(xiàn)問題)
user nobody nobody; #啟動nginx服務(wù)的用戶與組
worker_processes 2; #啟動nginx服務(wù)的工作進(jìn)程
error_log logs/nginx_error.log crit; #錯誤日志,以及等級
pid /usr/local/nginx/logs/nginx.pid; #nginx服務(wù)進(jìn)程PID
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri"$status'
'"$http_referer""$http_user_agent"'
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m ;
client_body_timeout 3m ;
send_timeout 3m ;
connection_pool_size 256 ;
client_header_buffer_size 1k ;
large_client_header_buffers 8 4k ;
request_pool_size 4k ;
output_buffers 4 32k ;
postpone_output 1460 ;
client_max_body_size 10m ;
client_body_buffer_size 10m ;
client_body_temp_path /usr/local/nginx/client_body_temp ;
proxy_temp_path /usr/local/nginx/proxy_temp ;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp ;
fastcgi_intercept_errors on ;
tcp_nodelay on ;
gzip_min_length 1k ;
gzip_buffers 4 8k ;
gzip_comp_level 5 ;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript/css text/htm ;
#application/xml;
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php ;
root /usr/local/http;
location ~\.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock ;
fastcgi_index index.php ;
fastcgi_param SCRIPT_FILENAME /usr/local/http$fastcgi_script_name ;
}
}
}
nginx啟動腳本(根據(jù)自己nginx所在目錄修改)
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/var/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc nginx -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
給予啟動文件權(quán)限
chmod 755 /etc/init.d/nginx
將nginx加入系統(tǒng)開機(jī)啟動
chkconfig --add nginx
chkconfig nginx on
nginx跟php有兩種通信方式
php配置文件中修改通信方式
listen = /tmp/php-fcgi.sock 或
listen = 127.0.0.1:9000
nginx配置文件中修改
在 location ~\.php$
{
下找到fastcgi_pass unix:/tmp/php-fcgi.sock ;
修改成和php中相同通信方式
fastcgi_pass unix:/tmp/php-fcgi.sock ; 或
fastcgi_pass 127.0.0.1:9000 ;
nginx虛擬主機(jī)
在主配置文件中添加
include vhosts/*.conf;
并在當(dāng)前目錄下創(chuàng)建vhosts目錄
mkdir vhosts
在此目錄下創(chuàng)建以.conf結(jié)尾的虛擬主機(jī)配置文件,寫入如下內(nèi)容
server
{
listen 80 ;
server_name 網(wǎng)站域名;
index index.html index.htm index.php ;
root /網(wǎng)頁目錄;
location ~\.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock ;
fastcgi_index index.php ;
fastcgi_param SCRIPT_FILENAME /網(wǎng)頁目錄$fastcgi_script_name ;
}
}
也可以直接在主配置文件中復(fù)制server段內(nèi)容進(jìn)行修改
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。