nginx.conf中配置:
server {listen 8001;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root /opt/nginx/html;index index.html index.php;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;include fastcgi_params;}}
管理FastCGI進程:
啟動兩種方式:
/usr/local/php/bin/php-cgi --fpm
或者
/usr/local/php/sbin/php-fpm start
平滑啟動nginx程式:
kill -HUP `/opt/nginx/logs/nginx.pid`
最佳化nginx中FastCGI參數:
fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m; #為fastcgi緩衝制定一個檔案路徑、目錄結構、關鍵字地區儲存時間和非活動刪除時間fastcgi_connect_timeout 300;#指定串連到後端的fastcgi的逾時時間fastcgi_send_timeout 300;#指定向fastcgi傳輸請求的逾時時間fastcgi_read_timeout 300;#指定接收fastcgi應答的逾時時間fastcgi_buffer_size 64k;#讀取fastcgi應答第一部分需要多大的緩衝fastcgi_buffers 4 64k;#指定本地需要多少和多大的緩衝區來緩衝fastcgi的應答請求fastcgi_busy_buffers_size 128k;#預設是fastcgi_buffer的兩倍fastcgi_temp_file_write_size 128k;#表示寫入快取檔案時使用多大的資料區塊fastcgi_cache TEST;#開啟緩衝並指定名稱fastcgi_cache_valid 200 302 1h;#指定應答代碼的緩衝時間fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m;