Apache下,每一個虛擬主機能夠單獨不一樣的phpadminvalue,能夠設置很是詳細的網站目錄權限設置,安全性比較高。php
nginx作爲一個高性能的web服務器已經獲得普遍的應用,隨着php5.3的發佈,php-fpm也已經內置在php裏面了,如何安裝配置nginx+php-fpm,下面的內容,將集中於給nginx的虛擬主機和php-fpm的pools配合,實現不一樣虛擬主機運行不一樣配置的php。nginx
咱們下面會配置兩個虛擬主機,使用不一樣的php和php-fpm配置web
編輯php-fpm.conf安全
幫助服務器
01
02
03
04
05
|
[global]
pid =
/usr/local/php/var/run/php-fpm
.pid
error_log =
/usr/local/php/var/log/php-fpm
.log
log_level = warning
emergency_restart_threshold = 0
emergency_restart_interval = 0
process_control_timeout = 0
daemonize =
yes
include=
/srv/vhost/
*
/php-fpm
.conf
|
這裏第10行包含各vhost的配置函數
編輯/srv/vhost/a/php-fpm.confphp-fpm
幫助性能
01
02
03
04
05
06
07
08
09
10
11
12
|
[a]
listen =
/srv/vhost/a/php-fpm
.sock
; Unix user
/group
of processes
user = nginx
group = nginx
; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 100
; Pass environment variables
env
[HOSTNAME] = $HOSTNAME
env
[PATH] =
/usr/local/bin
:
/usr/bin
:
/bin
env
[TMP] =
/tmp
env
[TMPDIR] =
/tmp
env
[TEMP] =
/tmp
; host-specific php ini settings here
php_admin_value[disable_functions]=phpinfo
php_admin_value[open_basedir]=
/srv/vhost/a/webroot
:
/tmp
|
當php-fpm和nginx在同一臺服務器時,我比較喜歡用unix sockt。這裏指定了sockt文件的地址 /srv/vhost/a/php-fpm.sock網站
編輯 /srv/vhost/b/php-fpm.confspa
01
02
03
04
05
06
07
08
09
10
11
12
|
[b]
listen =
/srv/vhost/b/php-fpm
.sock
; Unix user
/group
of processes
user = nginx
group = nginx
; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 100
; Pass environment variables
env
[HOSTNAME] = $HOSTNAME
env
[PATH] =
/usr/local/bin
:
/usr/bin
:
/bin
env
[TMP] =
/tmp
env
[TMPDIR] =
/tmp
env
[TEMP] =
/tmp
; host-specific php ini settings here
;php_admin_value[disable_functions]=phpinfo
php_admin_value[open_basedir]=
/srv/vhost/a/webroot
:
/tmp
|
監聽在 /srv/vhost/b/php-fpm.sock,另外能夠看到,我註釋了phpadminvalue[disable_functions]=phpinfo,也就是不由用phpinfo函數
php-fpm配置完畢,啓動它。
接下來配置nginx,配置兩個server
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
server {
listen 80;
server_name a.somethings.me;
index index.php;
root
/srv/vhost/a/webroot/
;
location /{
}
location ~ .*\.php${
fastcgi_pass unix:
/srv/vhost/a/php-fpm
.sock;
fastcgi_index index.php;
include fcgi.conf;
}
access_log
/var/log/nginx/a
.somethines.me-access.log;
}
server {
listen 80;
server_name b.somethings.me;
index index.php;
root
/srv/vhost/a/webroot/
;
location /{
}
location ~ .*\.php${
fastcgi_pass unix:
/srv/vhost/b/php-fpm
.sock;
fastcgi_index index.php;
include fcgi.conf;
}
access_log
/var/log/nginx/b
.somethines.me-access.log;
}
|
兩個server分別fastcgi_pass到不一樣的sockte文件上,分別在/srv/vhost/a/webroot/ 和 /srv/vhost/a/webroot/ 下建立以下文件
1
|
<?php phpinfo();
|
啓動nginx,分別訪問 a.somethings.me 和 b.somethings.me 發現a.somethings.me 報錯以下
1
|
Warning: phpinfo() has been disabled
for
security reasons
in
/srv/vhost/a/webroot/phpinfo
.php on line 2
|