我是靠谱客的博主 风中菠萝,最近开发中收集的这篇文章主要介绍nginx keepalive设置,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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;
	
	client_max_body_size 20M;
    client_header_buffer_size  32k;
    large_client_header_buffers 4 32k;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

	proxy_buffer_size 64k;
    proxy_buffers   32 32k;
    proxy_busy_buffers_size 128k;
	
	upstream aauCfg_backend {
		server  127.0.0.1:97;
		keepalive 16;
	}
	
	upstream HFC_backend {
		server  127.0.0.1:8090;
		keepalive 16;
	}
	
	upstream manager_backend {
		server  127.0.0.1:8095;
		keepalive 16;
	}
	
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

		root   html/tools;
        index  index.html index.htm index.php;
		
		proxy_http_version 1.1;
		proxy_set_header  Connection  "";
		proxy_set_header  Host  $host;
        proxy_set_header  X-Real_IP  $remote_addr;
        proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
		
        location / {
			if (!-e $request_filename) {
                #rewrite  ^/(.*)$  /index.php/$1  last;
                #break;
                rewrite ^/(.*)$ /index.php/$1;
            }
        }
		
		location ~* .(ico|css|js|gif|jpe?g|png)(?[0-9]+)?$ {
                expires max;
                log_not_found off;
        }
		
        location ^~ /aauCfg/ {
            #proxy_pass   http://$remote_addr:97$request_uri;
			proxy_pass   http://aauCfg_backend;
        }
		
        location ^~ /HFC/ {
            #proxy_pass   http://$remote_addr:8090$request_uri;
			proxy_pass   http://HFC_backend;
        }
		
        location ^~ /manager/ {
            #proxy_pass   http://$remote_addr:8095$request_uri;
			proxy_pass   http://manager_backend;
        }
		
        #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$ {
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
		
		location ~ .php
        {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi.conf;
            include        fastcgi_params;

            #定义变量 $path_info ,用于存放pathinfo信息
            set $path_info "";
            #定义变量 $real_script_name,用于存放真实地址
            set $real_script_name $fastcgi_script_name;
            #如果地址与引号内的正则表达式匹配
            if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
                    #将文件地址赋值给变量 $real_script_name
                    set $real_script_name $1;
                    #将文件地址后的参数赋值给变量 $path_info
                    set $path_info $2;
            }
            #配置fastcgi的一些参数
            fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
            fastcgi_param SCRIPT_NAME $real_script_name;
            fastcgi_param PATH_INFO $path_info;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

最后

以上就是风中菠萝为你收集整理的nginx keepalive设置的全部内容,希望文章能够帮你解决nginx keepalive设置所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部