CentOS 5.7, Nginx 1.06 PHP 5.2.17(php-fpm)
安装过程省略,我基本都是编译安装在 /usr/local/ 下面。
# VHOST include /vhost/*/*/nginx.conf;
<?xml version="1.0" ?> <configuration> <section name="global_options"> <value name="pid_file">/vhost/user1/qq.com/php-fpm.pid</value> <!-- 记录主进程pid --> <value name="error_log">/vhost/logs/user1_qq.com.log</value> <!-- 记录php-fpm错误日志 --> <value name="log_level">warn</value> <!-- 日志记录级别 --> <value name="emergency_restart_threshold">10</value> <value name="emergency_restart_interval">1m</value> <value name="process_control_timeout">5s</value> <value name="daemonize">yes</value> </section> <workers> <section name="pool"> <value name="name">user1_qq.com</value> <!-- 该pool名称,日志中使用 --> <value name="listen_address">/vhost/user1/qq.com/php-fpm.socket</value> <!-- 使用socket 文件,要和和nginx中一致 --> <value name="listen_options"> <value name="backlog">-1</value> <value name="owner"></value> <value name="group"></value> <value name="mode">0666</value> </value> <value name="php_defines"> <!-- 这里可以设置php.ini中的参数,指定的php.ini无法覆盖。 --> <!--<value name="disable_functions">phpinfo,exec,passthru,shell_exec,system,proc_open,popen,show_source</value> <value name="open_basedir">/tmp/:./:/home/user1/qq.com/</value>--> </value> <value name="user">user1</value> <!-- 执行php时的用户该用户有什么权限php就有什么权限~ --> <value name="group">user1</value> <!-- 执行php是的用户组 --> <value name="pm"> <value name="style">static</value> <value name="max_children">128</value> <value name="apache_like"> <value name="StartServers">10</value> <value name="MinSpareServers">5</value> <value name="MaxSpareServers">35</value> </value> </value> <value name="request_terminate_timeout">0s</value> <value name="request_slowlog_timeout">0s</value> <value name="slowlog">/vhost/logs/user1_qq.com_slow.log</value> <value name="rlimit_files">65535</value> <value name="rlimit_core">0</value> <value name="chroot"></value> <value name="chdir"></value> <value name="catch_workers_output">yes</value> <value name="max_requests">1024</value> <value name="allowed_clients">127.0.0.1</value> <value name="environment"> <value name="HOSTNAME">$HOSTNAME</value> <value name="PATH">/usr/local/bin:/usr/bin:/bin</value> <value name="TMP">/tmp</value> <value name="TMPDIR">/tmp</value> <value name="TEMP">/tmp</value> <value name="OSTYPE">$OSTYPE</value> <value name="MACHTYPE">$MACHTYPE</value> <value name="MALLOC_CHECK_">2</value> </value> </section> </workers> </configuration>有简单的注释,其他看 官方文档。
server { server_name www.qq.com qq.com; root /home/user1/qq.com/wwwroot/; access_log /home/user1/qq.com/logs/access.log; include /home/user1/qq.com/.nginx; location ~ \.php$ { fastcgi_pass unix:/vhost/user1/qq.com/php-fpm.socket; fastcgi_index index.php; include fcgi.conf; } include cache.conf; error_page 404 403 500 503 505 504 502 error_page 500 503 505 504 502 }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; }
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE 'Apache/2.2.17 (Unix) DAV/2 PHP/5.2.17'; 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;
#!/bin/sh # # php-fpm - this script starts and stops the php-fpm daemin # # chkconfig: - 85 15 # description: php-fpm # processname: php-fpm # config: /usr/local/php/etc/php-fpm.conf vhost=$2 php_fpm_BIN=/usr/local/php/bin/php-cgi php_fpm_CONF=/vhost/$vhost/php-fpm.conf php_fpm_PID=/vhost/$vhost/php-fpm.pid php_INI=/home/$vhost/php.ini php_opts="--fpm-config $php_fpm_CONF" if [ ! $vhost ]; then cat /vhost/hosts|while read line;do $0 $1 $line done exit fi if [ ! -r $php_fpm_CONF ]; then echo -n "不存在配置文件; $php_fpm_CONF" exit fi if [ -r $php_INI ]; then php_opts="$php_opts -c $php_INI" fi wait_for_pid () { try=0 while test $try -lt 35 ; do case "$1" in 'created') if [ -f "$2" ] ; then try='' break fi ;; 'removed') if [ ! -f "$2" ] ; then try='' break fi ;; esac echo -n . try=`expr $try + 1` sleep 1 done } case "$1" in start) if [ -f $php_fpm_PID ]; then echo 'Has started!' exit fi echo -n "Starting php_fpm ($vhost) " $php_fpm_BIN --fpm $php_opts if [ "$?" != 0 ] ; then echo " failed" exit 1 fi wait_for_pid created $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Shutting down php_fpm ($vhost)" if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -TERM `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; quit) echo -n "Gracefully shutting down php_fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -QUIT `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; restart) $0 stop $2 $0 start $2 ;; reload) echo -n "Reload service php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -USR2 `cat $php_fpm_PID` echo " done" ;; logrotate) echo -n "Re-opening php-fpm log file " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -USR1 `cat $php_fpm_PID` echo " done" ;; *) echo "Usage: $0 {start|stop|quit|restart|reload|logrotate}" exit 1 ;; esac
find /home/ -type f -exec chmod 0644 {} \; #设置文件问644 find /home/ -type d -exec chmod 0711 {} \; #设置目录问711
mkdir /home/$OWNER$/$DOMAIN$/ mkdir /home/$OWNER$/$DOMAIN$/logs/ mkdir /home/$OWNER$/$DOMAIN$/wwwroot/ touch /home/$OWNER$/$DOMAIN$/.nginx echo "$DOMAIN$" > /home/$OWNER$/$DOMAIN$/wwwroot/index.html chown $OWNER$:$OWNER$ /home/$OWNER$/ -R find /home/$OWNER$/ -type f -exec chmod 0644 {} \; find /home/$OWNER$/ -type d -exec chmod 0711 {} \;
原文:http://bee.glroomy.com/nginx-php-fpm-urlwrite-php-ini.html
ps:似乎这边排版好看点~我要update下我blog了~