linux服务器下LNMP安装与配置方法

2019-10-14 22:24:08丽君

events
{
  use epoll;
#网络I/O模型,建议linux使用epoll,FreeBSD使用kqueue
  worker_connections 65535;
#最大允许连接数
}
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延迟
  keepalive_timeout 65;
#保持连接时间

  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;
#fastcgi设置
  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;
#网络压缩设置
  #limit_zone  crawler  $binary_remote_addr  10m;
  server
  {
    listen       80;
#监听端口
    server_name  192.168.150.253;
#主机名,或IP。如果是主机名,要能够DNS解析

location / {
root  html;
#网站主目录。/usr/local/nginx/html/
index index.html index.htm index.php;
#默认网页顺序
}

    #limit_conn   crawler  20;   

    location ~ .*.(php|php5)?$
#~:匹配       后面正则表达式:.*任意字符  .点 php或php5结尾。碰到网页文
件名是.php或.php5结尾
    {    
root  html;
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
#连接fastcgi,用来解析php语句
      fastcgi_index index.php;
#首页为index.php
   #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
#启动fast-cgi,可以在每个服务中启动,也可以放入/usr/local/nginx/conf/fastcgi_params,每个server都可以享用
      include fastcgi_params;
#包括fastcgi_params中参数
    }

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$