nginx安装及配置支持php的教程(全)

2019-10-17 21:11:50王冬梅

--with-config-file-path=/usr/local/php/etc --enable-force-cgi-redirect 
# make && make install 
# cp php.ini-recommended /usr/local/php/etc/php.ini 
# vi /usr/local/php/php-fpm.conf

(1)<value name="listen_address">127.0.0.1:9000</value>修改为<value name="listen_address">IP:9000</value> 
//本机就用默认的127.0.0.1 

(2)下面这两行去掉注释并修改
<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
<value name="display_errors">1</value>
(3)<value name="user">nobody</value>   //去注释 
(4)<value name="group">nobody</value>  //去注释 
(5)<value name="allowed_clients">127.0.0.1</value>   //允许连接的PC,本机就用127.0.0.1
启动php-fpm# /usr/local/php/sbin/php-fpm start添加到自启动# echo "/usr/local/php/sbin/php-fpm start">>/etc/rc.local

5、修改Linux Nginx的配置文件,支持PHP


# vi /usr/local/nginx/conf/nginx.conf 
user  nobody; 
worker_processes  8; 
pid  /usr/local/nginx/logs/nginx.pid; 
worker_rlimit_nofile 1024; 
events 
{use epoll; 
worker_connections 1024;} 
http{ 
include   mime.types; 
default_type  application/octet-stream; 
server_names_hash_bucket_size 128; 
client_header_buffer_size 32k; 
large_client_header_buffers 4 32k; 
client_max_body_size 8m;
sendfile on; 
tcp_nopush on; 
keepalive_timeout 60; 
tcp_nodelay on; 
fastcgi_connect_timeout 300; 
fastcgi_send_timeout 300; 
fastcgi_read_timeout 300; 
fastcgi_buffer_size 64k; 
fastcgi_buffers 4 64k; 
fastcgi_busy_buffers_size 128k; 
fastcgi_temp_file_write_size 128k; 
gzip on; 
gzip_min_length  1k; 
gzip_buffers 4 16k; 
gzip_http_version 1.0; 
gzip_comp_level 2; 
gzip_types   text/plain application/x-javascript text/css application/xml; 
gzip_vary on; 

server { 
listen   80; 
server_name  www.abcdefg.com; 
root   /var/www/blog; 
index  index.html index.htm index.php; 
location ~ .*.(php|php5)?$ { 
root   html; 
fastcgi_pass   127.0.0.1:9000; 
fastcgi_index  index.php; 
fastcgi_param  SCRIPT_FILENAME  /var/www/blog$fastcgi_script_name; 
includefastcgi_params;} 
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ 
{expires  30d;} 
location ~ .*.(js|css)?$ 
{expires  1h;}
log_format  access  '$remote_addr - $remote_user [$time_local] "$request" ' 
'$status $body_bytes_sent "$http_referer" ' 
'"$http_user_agent" $http_x_forwarded_for';