admin

NGINX 配置文件

admin linux 2023-01-25 466浏览 0

NGINX安装比较方便,但安装好以后的配置文件的优化却是有许多的学问,在此共享出本人NGINX的配置文件,有不足的地方请多多指教

如下是nginx.conf的配置文件
———————————————-华丽的分割线———————————————————

user  www www;
worker_processes 8;
error_log  logs/error.log  crit;
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}

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

  #charset  utf-8;

  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 30m;

  sendfile on;
  tcp_nopush     on;

  keepalive_timeout 60;

  tcp_nodelay on;

  client_body_buffer_size  512k;
  proxy_connect_timeout    5;
  proxy_read_timeout       60;
  proxy_send_timeout       5;
  proxy_buffer_size        16k;
  proxy_buffers            4 64k;
  proxy_busy_buffers_size 128k;
  proxy_temp_file_write_size 128k;

  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.1;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
  #限制并发和速率
  #limit_zone   one  $remote_addr  10m;

  include upstream.conf;

  include host/*.conf;

———————————————-华丽的分割线———————————————————

 

一下是在conf/host目录下的www.411c.com.conf的配置文件

———————————————-华丽的分割线———————————————————

server {
        include /usr/local/nginx/conf/port.conf;
        server_name  www.411c.com 411c.com;
        if ($host != 'www.411c.com' ) {
        rewrite ^/(.*)$ http://www.411c.com/$1 permanent;
        }
        error_page 403 http://www.411c.com;
        error_page 404 http://www.411c.com;

        root   /data/www/www.411c.com;

        location / {
            index  index.php index.htm;
        }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|txt)$
        {
        expires       7d;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /data/www/www.411c.com$fastcgi_script_name;
            include        fastcgi_params;
        }

        location /411c_nginx {
                       stub_status on;
                }

    log_format  411clog  '$remote_addr – $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" $http_x_forwarded_for';
        access_log  logs/411c.log  411clog;

———————————————-华丽的分割线———————————————————

 

如果要用到path_info我的配置文件如下:www.411c.com.conf

———————————————-华丽的分割线———————————————————

server {
        include /usr/local/nginx/conf/port.conf;
        server_name  www.411c.com 411c.com;
        if ($host != 'www.411c.com' ) {
        rewrite ^/(.*)$ http://www.411c.com/$1 permanent;
        }

        #charset utf8;
        #access_log  logs/host.access.log  main;
        include /data/www/www.411c.com/rewrite.conf;
        root   /data/www/www.411c.com;

        location / {
            index  index.html index.php;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|css|txt)$
        {
           expires       7d;
        }

        error_page  404   http://www.411c.com;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ ^(.+\.php)(.*)$ {
        root    /data/www/www.411c.com;
                fastcgi_index index.php;

                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param   PATH_INFO       $fastcgi_path_info;
                fastcgi_param   PATH_TRANSLATED $document_root$fastcgi_path_info;
                fastcgi_pass 127.0.0.1:9000;
                include fastcgi_params;
        }

                location /411c_nginx {
                        stub_status on;
                }
        log_format  411clog  '$remote_addr – $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" $http_x_forwarded_for';
        access_log  logs/411c.log  411clog;
}

———————————————-华丽的分割线———————————————————

再次申明,这些nginx配置文档都是本博客网站的配置文档,如果有什么配置不当的,请多指点

转载请注明:IT运维空间 » linux » NGINX 配置文件

继续浏览有关 LINUX技术 的文章
发表评论