Nginx、mysql、php-fpm安装与配置高性能Nginx平台

发布时间:2020-09-27编辑:脚本学堂
本文介绍rhel4.7与centos5.5环境下,搭建与配置Nginx、mysql、php-fpm环境的教程,有需要的朋友,可以参考下。

  vi /usr/local/nginx/conf/nginx.conf
写入以下内容:
 

复制代码 代码示例:

user www www;

worker_processes 8;
worker_cpu_affinity 0001 0010 0100 1000 0001 0010 0100 1000;

#error_log  /usr/local/nginx/logs/error.log;
#error_log  /usr/local/nginx/logs/error.log  notice;
#error_log  /usr/local/nginx/logs/error.log  info;

#pid        logs/nginx.pid;

worker_rlimit_nofile 204800;

events {
 use epoll;
 worker_connections 204800;
}

http {
 include       mime.types;
 default_type  application/octet-stream;

 #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 #                  '$status $body_bytes_sent "$http_referer" '
 #                  '"$http_user_agent" "$http_x_forwarded_for"';

 #access_log  logs/access.log  main;

 sendfile        on;
 tcp_nopush     on;
 tcp_nodelay    on;
 keepalive_timeout  60;
 #ip_hash;

 ignore_invalid_headers   on;
 recursive_error_pages    on;
 server_name_in_redirect off;
 server_tokens           off;

 gzip on;
 gzip_comp_level  9;
 gzip_min_length  1100;
 gzip_buffers  4 8k;
 gzip_http_version  1.1;
 gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

 server_names_hash_bucket_size 256;
 client_header_buffer_size 16K;
 large_client_header_buffers 4 64k;
 client_max_body_size             50m;
 client_body_buffer_size        256k;
 client_header_timeout     3m;
 client_body_timeout 3m;
 send_timeout             3m;

 open_file_cache max=204800 inactive=20s;
 open_file_cache_min_uses 1;
 open_file_cache_valid 30s;
  
 server
 {
  listen       80;
  server_name www.jb200.com;
  index index.html index.php;
  root  /home/www/blog;
  access_log  /home/logs/access_lihuipeng.www.jb200.com.log;
  
  if (-d $request_filename){
   rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  }
   
  error_page   500 502 503 504 404 403 http://www.jb200.com;
   
  location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
   expires 30d;
  }

  location ~ .*.(js|css)?$ {
   expires 6h;
  }

  location ~ .*.(log|txt)$
  {
   deny all;
  }

   location ~ .*.(php)?$
  {
   fastcgi_pass  127.0.0.1:9000;
   fastcgi_index index.php;
   include fcgi.conf;
  }
 }
}

7、启动服务
 

复制代码 代码示例:
/usr/local/php/sbin/php-fpm start
/usr/local/nginx/sbin/nginx

检查是否成功启动:
 

复制代码 代码示例:
 [root@localhost ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name 
tcp        0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN      3937/snmpd        
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      3954/php-cgi      
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      2662/mysqld       
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      18066/nginx       
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      17955/vsftpd      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      4137/sendmail: acce
tcp        0      0 :::5989                     :::*                        LISTEN      2714/cimserver    
tcp        0      0 :::22                       :::*                        LISTEN      2574/sshd         
udp        0      0 0.0.0.0:161                 0.0.0.0:*                               3937/snmpd

可见php-cgi和nginx端口已经正常监听了。