{"id":29777,"date":"2022-12-10T05:37:23","date_gmt":"2022-12-09T21:37:23","guid":{"rendered":"http:\/\/gulass.cn\/?p=29777"},"modified":"2022-12-10T05:37:38","modified_gmt":"2022-12-09T21:37:38","slug":"nginx-config-optimization","status":"publish","type":"post","link":"https:\/\/gulass.cn\/nginx-config-optimization.html","title":{"rendered":"Nginx\u6e90\u7801\u5b89\u88c5\u53ca\u8c03\u4f18\u914d\u7f6e"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u7531\u4e8eNginx\u672c\u8eab\u7684\u4e00\u4e9b\u4f18\u70b9\uff0c\u8f7b\u91cf\uff0c\u5f00\u6e90\uff0c\u6613\u7528\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u516c\u53f8\u4f7f\u7528nginx\u4f5c\u4e3a\u81ea\u5df1\u516c\u53f8\u7684web\u5e94\u7528\u670d\u52a1\u5668\uff0c\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecdnginx\u6e90\u7801\u5b89\u88c5\u7684\u540c\u65f6\u5e76\u5bf9nginx\u8fdb\u884c\u4f18\u5316\u914d\u7f6e\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"nginx-logo\"<\/a><\/p>\n

Nginx\u7f16\u8bd1\u524d\u7684\u4f18\u5316<\/strong><\/div>\n
[root@linuxprobe ~]# wget http:\/\/nginx.org\/download\/nginx-1.10.1.tar.gz\r\n[root@linuxprobe ~]# tar xvf nginx-1.10.1.tar.gz -C \/usr\/local\/src\/\r\n[root@linuxprobe ~]# cd \/usr\/local\/src\/nginx-1.10.1\/<\/pre>\n

\u7f16\u8bd1\u524d\u7684\u4f18\u5316\u4e3b\u8981\u662f\u7528\u6765\u4fee\u6539\u7a0b\u5e8f\u540d\u7b49\u7b49\uff0c\u4f8b\u5982\uff1a<\/strong><\/p>\n

[root@linuxprobe nginx-1.10.1]# curl -I http:\/\/www.baidu.com\r\n\u2026\u2026\r\nServer: bfe\/1.0.8.14\r\n\u2026\u2026\r\n[root@linuxprobe nginx-1.10.1]# curl -I http:\/\/www.sina.com.cn\r\n\u2026\u2026\r\nServer: nginx\r\n\u2026\u2026<\/pre>\n
[root@linuxprobe nginx-1.10.1]# curl -I http:\/\/gulass.cn\r\nHTTP\/1.1 200 OK\r\nServer: nginx\/1.10.1 #\u6211\u4eec\u76ee\u6807\u662f\u5c06nginx\u66f4\u6539\u540d\u5b57\r\nContent-Type: text\/html; charset=UTF-8\r\nConnection: keep-alive\r\nX-Powered-By: PHP\/5.6.29\r\nSet-Cookie: PHPSESSID=smm0i6u4f9v7bj0gove79ja1g7; path=\/\r\nCache-Control: no-cache\r\nDate: Mon, 07 Seq 2016 06:09:11 GMT<\/pre>\n
[root@linuxprobe nginx-1.10.1]# vim src\/core\/nginx.h<\/pre>\n

<\/p>\n

  • \u76ee\u7684\u66f4\u6539\u6e90\u7801\u9690\u85cf\u8f6f\u4ef6\u540d\u79f0\u548c\u7248\u672c\u53f7<\/li>\n

    <\/strong><\/p>\n

    #define NGINX_VERSION \"nginx_stable\" #\u6b64\u884c\u4fee\u6539\u7684\u662f\u4f60\u60f3\u8981\u7684\u7248\u672c\u53f7<\/p>\n

    #define NGINX_VER \"linuxprobe\/\" NGINX_VERSION #\u6b64\u884c\u4fee\u6539\u7684\u662f\u4f60\u60f3\u4fee\u6539\u7684\u8f6f\u4ef6\u540d\u79f0<\/p>\n

    [root@linuxprobe nginx-1.10.1]# vim +49 src\/http\/ngx_http_header_filter_module.c<\/pre>\n

    <\/p>\n

  • \u4fee\u6539HTTP\u5934\u4fe1\u606f\u4e2d\u7684connection\u5b57\u6bb5\uff0c\u9632\u6b62\u56de\u663e\u5177\u4f53\u7248\u672c\u53f7<\/li>\n

    <\/strong><\/p>\n

    \u62d3\u5c55\uff1a\u901a\u7528http\u5934\u57df<\/p>\n

    \u901a\u7528\u5934\u57df\u5305\u542b\u8bf7\u6c42\u548c\u54cd\u5e94\u6d88\u606f\u90fd\u652f\u6301\u7684\u5934\u57df\uff0c\u901a\u7528\u5934\u57df\u5305\u542bCache-Control\u3001 Connection\u3001Date\u3001Pragma\u3001Transfer-Encoding\u3001Upgrade\u3001Via\u3002\u5bf9\u901a\u7528\u5934\u57df\u7684\u6269\u5c55\u8981\u6c42\u901a\u8baf\u53cc\u65b9\u90fd\u652f\u6301\u6b64\u6269\u5c55\uff0c\u5982\u679c\u5b58\u5728\u4e0d\u652f\u6301\u7684\u901a\u7528\u5934\u57df\uff0c\u4e00\u822c\u5c06\u4f1a\u4f5c\u4e3a\u5b9e\u4f53\u5934\u57df\u5904\u7406\u3002\u90a3\u4e48\u4e5f\u5c31\u662f\u8bf4\u6709\u90e8\u5206\u8bbe\u5907\uff0c\u6216\u8005\u662f\u8f6f\u4ef6\uff0c\u80fd\u83b7\u53d6\u5230connection\uff0c\u90e8\u5206\u4e0d\u80fd\uff0c\u8981\u9690\u85cf\u5c31\u8981\u5f7b\u5e95\uff01<\/p>\n

    static char ngx_http_server_string[] = \"Server: LinuxprobeWeb\" CRLF;<\/p>\n

    [root@linuxprobe nginx-1.10.1]# vim +29 src\/http\/ngx_http_special_response.c<\/pre>\n

    <\/p>\n

  • \u5b9a\u4e49\u4e86http\u9519\u8bef\u7801\u7684\u8fd4\u56de<\/li>\n

    <\/strong><\/p>\n

    \u6709\u65f6\u5019\u6211\u4eec\u9875\u9762\u7a0b\u5e8f\u51fa\u73b0\u9519\u8bef\uff0cNginx\u4f1a\u4ee3\u6211\u4eec\u8fd4\u56de\u76f8\u5e94\u7684\u9519\u8bef\u4ee3\u7801\uff0c\u56de\u663e\u7684\u65f6\u5019\uff0c\u4f1a\u5e26\u4e0anginx\u548c\u7248\u672c\u53f7\uff0c\u6211\u4eec\u628a\u4ed6\u9690\u85cf\u8d77\u6765<\/p>\n

    static u_char ngx_http_error_full_tail[]<\/strong> =<\/strong>\r\n\"<hr><center>\" NGINX_VER \"<\/center>\" CRLF\r\n\"<\/body>\" CRLF\r\n\"<\/html>\" CRLF\r\n;<\/strong><\/pre>\n

    \u4fee\u6539\u540e<\/p>\n

    static u_char ngx_http_error_tail[]<\/strong> =<\/strong>\r\n\"<hr><center>LinuxprobeWeb<\/center>\" CRLF\r\n\"<\/body>\" CRLF\r\n\"<\/html>\" CRLF\r\n;<\/strong><\/pre>\n
    Nginx\u6b63\u5f0f\u5b89\u88c5<\/strong><\/div>\n
    \u4e00\u952e\u5b89\u88c5\u76f8\u5173\u4f9d\u8d56\u5305<\/strong><\/span><\/div>\n
    [root@linuxprobe nginx-1.10.1]# yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel -y<\/pre>\n
    \u5b89\u88c5pcre\u4f9d\u8d56<\/strong><\/span><\/div>\n

    #\u672c\u5730\u4e0b\u8f7dpcre\u4e0a\u4f20\u5230\u670d\u52a1\u5668<\/p>\n

    [root@linuxprobe]# tar zxvf \/usr\/local\/src\/pcre-8.36.tar.gz -C \/usr\/local\/src\/\r\n[root@linuxprobe nginx-1.10.1]# cd  \/usr\/local\/src\/pcre-8.36\r\n[root@linuxprobe nginx-1.10.1]# .\/configure &&\u3000make && make install\r\n[root@linuxprobe nginx-1.10.1]# .\/configure --prefix=\/usr\/local\/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=\/usr\/local\/src\/pcre-8.36 --with-openssl=\/usr\/include\/openssl<\/pre>\n
    \u6ce8\u610f\uff1aTCP_FASTOPEN \u53ea\u5728 3.7.1 \u4ee5\u53ca\u66f4\u65b0\u7684 Linux \u5185\u6838\u7248\u672c\u624d\u652f\u6301\r\n--with-http_dav_module             #\u542f\u7528\u652f\u6301\uff08\u589e\u52a0PUT,DELETE,MKCOL\uff1a\u521b\u5efa\u96c6\u5408\uff0cCOPY\u548cMOVE\u65b9\u6cd5\uff09\u9ed8\u8ba4\u5173\u95ed\uff0c\u9700\u8981\u7f16\u8bd1\u5f00\u542f\r\n--with-http_stub_status_module     #\u542f\u7528\u652f\u6301\uff08\u83b7\u53d6Nginx\u4e0a\u6b21\u542f\u52a8\u4ee5\u6765\u7684\u5de5\u4f5c\u72b6\u6001\uff09\r\n--with-http_addition_module        #\u542f\u7528\u652f\u6301\uff08\u4f5c\u4e3a\u4e00\u4e2a\u8f93\u51fa\u8fc7\u6ee4\u5668\uff0c\u652f\u6301\u4e0d\u5b8c\u5168\u7f13\u51b2\uff0c\u5206\u90e8\u5206\u76f8\u5e94\u8bf7\u6c42\uff09\r\n--with-http_sub_module             #\u542f\u7528\u652f\u6301\uff08\u5141\u8bb8\u4e00\u4e9b\u5176\u4ed6\u6587\u672c\u66ff\u6362Nginx\u76f8\u5e94\u4e2d\u7684\u4e00\u4e9b\u6587\u672c\uff09\r\n--with-http_flv_module             #\u542f\u7528\u652f\u6301\uff08\u63d0\u4f9b\u652f\u6301flv\u89c6\u9891\u6587\u4ef6\u652f\u6301\uff09\r\n--with-http_mp4_module             #\u542f\u7528\u652f\u6301\uff08\u63d0\u4f9b\u652f\u6301mp4\u89c6\u9891\u6587\u4ef6\u652f\u6301\uff0c\u63d0\u4f9b\u4f2a\u6d41\u5a92\u4f53\u670d\u52a1\u7aef\u652f\u6301\uff09\r\n--with-pcre=\/usr\/local\/src\/pcre-8.36            #\u9700\u8981\u6ce8\u610f\uff0c\u8fd9\u91cc\u6307\u7684\u662f\u6e90\u7801,\u7528#.\/configure --help |grep pcre\u67e5\u770b\u5e2e\u52a9<\/pre>\n
    [root@linuxprobe nginx-1.10.1]# make && make install<\/pre>\n
    #Nginx\u5b89\u88c5\u8def\u5f84\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a \/usr\/local\/nginx\u3002\r\n--prefix=PATH       #Nginx\u53ef\u6267\u884c\u6587\u4ef6\u5b89\u88c5\u8def\u5f84\u3002\u53ea\u80fd\u5b89\u88c5\u65f6\u6307\u5b9a\uff0c\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3aPATH\/sbin\/nginx\u3002\r\n--sbin-path=PATH    #\u5728\u6ca1\u6709\u7ed9\u5b9a-c\u9009\u9879\u4e0b\u9ed8\u8ba4\u7684nginx.conf\u7684\u8def\u5f84\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3aPATH\/conf\/nginx.conf\u3002 \r\n--conf-path=PATH    #\u5728nginx.conf\u4e2d\u6ca1\u6709\u6307\u5b9apid\u6307\u4ee4\u7684\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u7684nginx.pid\u7684\u8def\u5f84\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a PATH\/logs\/nginx.pid\u3002\r\n--pid-path=PATH     #nginx.lock\u6587\u4ef6\u7684\u8def\u5f84\u3002\r\n--lock-path=PATH    #\u5728nginx.conf\u4e2d\u6ca1\u6709\u6307\u5b9aerror_log\u6307\u4ee4\u7684\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u7684\u9519\u8bef\u65e5\u5fd7\u7684\u8def\u5f84\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a PATH\/logs\/error.log\u3002\r\n--error-log-path=PATH    #\u5728nginx.conf\u4e2d\u6ca1\u6709\u6307\u5b9aaccess_log\u6307\u4ee4\u7684\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u7684\u8bbf\u95ee\u65e5\u5fd7\u7684\u8def\u5f84\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a PATH\/logs\/access.log\u3002\r\n--http-log-path=PATH     #\u5728nginx.conf\u4e2d\u6ca1\u6709\u6307\u5b9auser\u6307\u4ee4\u7684\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u7684nginx\u4f7f\u7528\u7684\u7528\u6237\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a nobody\u3002\r\n--user=USER       #\u5728nginx.conf\u4e2d\u6ca1\u6709\u6307\u5b9auser\u6307\u4ee4\u7684\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u7684nginx\u4f7f\u7528\u7684\u7ec4\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a nobody\u3002\r\n--group=GROUP     #\u6307\u5b9a\u7f16\u8bd1\u7684\u76ee\u5f55\r\n--builddir=DIR    #\u542f\u7528 rtsig \u6a21\u5757\r\n--with-rtsig_module    #\u5141\u8bb8\u6216\u4e0d\u5141\u8bb8\u5f00\u542fSELECT\u6a21\u5f0f\uff0c\u5982\u679cconfigure\u6ca1\u6709\u627e\u5230\u5408\u9002\u7684\u6a21\u5f0f\uff0c\u6bd4\u5982\uff0ckqueue(sun os)\u3001epoll(linux kenel 2.6+)\u3001rtsig(\u5b9e\u65f6\u4fe1\u53f7)\r\n--with-select_module(--without-select_module)    #\u5141\u8bb8\u6216\u4e0d\u5141\u8bb8\u5f00\u542fPOLL\u6a21\u5f0f\uff0c\u5982\u679c\u6ca1\u6709\u5408\u9002\u7684\uff0c\u5219\u5f00\u542f\u8be5\u6a21\u5f0f\u3002\r\n--with-poll_module(--without-poll_module)        #\u5f00\u542fHTTP SSL\u6a21\u5757\uff0c\u4f7fNGINX\u53ef\u4ee5\u652f\u6301HTTPS\u8bf7\u6c42\u3002\u8fd9\u4e2a\u6a21\u5757\u9700\u8981\u5df2\u7ecf\u5b89\u88c5\u4e86OPENSSL\uff0c\u5728DEBIAN\u4e0a\u662flibssl-dev\r\n\r\n--with-http_ssl_module         #\u542f\u7528ngx_http_ssl_module\r\n--with-http_realip_module      #\u542f\u7528 ngx_http_realip_module\r\n--with-http_addition_module    #\u542f\u7528 ngx_http_addition_module\r\n--with-http_sub_module    #\u542f\u7528 ngx_http_sub_module\r\n--with-http_dav_module    #\u542f\u7528 ngx_http_dav_module\r\n--with-http_flv_module    #\u542f\u7528 ngx_http_flv_module\r\n--with-http_stub_status_module    #\u542f\u7528 \"server status\" \u9875\r\n--without-http_charset_module     #\u7981\u7528 ngx_http_charset_module\r\n--without-http_gzip_module        #\u7981\u7528 ngx_http_gzip_module. \u5982\u679c\u542f\u7528\uff0c\u9700\u8981 zlib \u3002\r\n--without-http_ssi_module         #\u7981\u7528 ngx_http_ssi_module\r\n--without-http_userid_module      #\u7981\u7528 ngx_http_userid_module\r\n--without-http_access_module      #\u7981\u7528 ngx_http_access_module\r\n--without-http_auth_basic_module  #\u7981\u7528 ngx_http_auth_basic_module\r\n--without-http_autoindex_module   #\u7981\u7528 ngx_http_autoindex_module\r\n--without-http_geo_module         #\u7981\u7528 ngx_http_geo_module\r\n--without-http_map_module         #\u7981\u7528 ngx_http_map_module\r\n--without-http_referer_module     #\u7981\u7528 ngx_http_referer_module\r\n--without-http_rewrite_module     #\u7981\u7528 ngx_http_rewrite_module. \u5982\u679c\u542f\u7528\u9700\u8981 PCRE \u3002\r\n--without-http_proxy_module       #\u7981\u7528 ngx_http_proxy_module\r\n--without-http_fastcgi_module     #\u7981\u7528 ngx_http_fastcgi_module\r\n--without-http_memcached_module   #\u7981\u7528 ngx_http_memcached_module\r\n--without-http_limit_zone_module  #\u7981\u7528 ngx_http_limit_zone_module\r\n--without-http_empty_gif_module   #\u7981\u7528 ngx_http_empty_gif_module\r\n--without-http_browser_module     #\u7981\u7528 ngx_http_browser_module\r\n--without-http_upstream_ip_hash_module   #\u7981\u7528 ngx_http_upstream_ip_hash_module\r\n--with-http_perl_module -         #\u542f\u7528 ngx_http_perl_module\r\n--with-perl_modules_path=PATH     #\u6307\u5b9a perl \u6a21\u5757\u7684\u8def\u5f84\r\n--with-perl=PATH        #\u6307\u5b9a perl \u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\r\n--http-log-path=PATH    #Set path to the http access log\r\n--http-client-body-temp-path=PATH    #Set path to the http client request body temporary files\r\n--http-proxy-temp-path=PATH          #Set path to the http proxy temporary files\r\n--http-fastcgi-temp-path=PATH        #Set path to the http fastcgi temporary files\r\n--without-http                 #\u7981\u7528 HTTP server\r\n--with-mail                    #\u542f\u7528 IMAP4\/POP3\/SMTP \u4ee3\u7406\u6a21\u5757\r\n--with-mail_ssl_module         #\u542f\u7528 ngx_mail_ssl_module\r\n--with-cc=PATH                 #\u6307\u5b9a C \u7f16\u8bd1\u5668\u7684\u8def\u5f84\r\n--with-cpp=PATH                #\u6307\u5b9a C \u9884\u5904\u7406\u5668\u7684\u8def\u5f84\r\n--with-cc-opt=OPTIONS #\r\n--with-ld-opt=OPTIONS #Additional parameters passed to the linker. With the use of the system library PCRE in FreeBSD, it is necessary to indicate --with-ld-opt=\"-L \/usr\/local\/lib\".\r\n--with-cpu-opt=CPU        #\u4e3a\u7279\u5b9a\u7684CPU\u7f16\u8bd1\uff0c\u6709\u6548\u7684\u503c\u5305\u62ec\uff1apentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64\r\n--without-pcre            #\u7981\u6b62PCRE\u5e93\u7684\u4f7f\u7528\u3002\u540c\u65f6\u4e5f\u4f1a\u7981\u6b62 HTTP rewrite \u6a21\u5757\u3002\u5728 \"location\" \u914d\u7f6e\u6307\u4ee4\u4e2d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u4e5f\u9700\u8981 PCRE \u3002\r\n--with-pcre=DIR           #\u6307\u5b9a PCRE \u5e93\u7684\u6e90\u4ee3\u7801\u7684\u8def\u5f84\u3002\r\n--with-pcre-opt=OPTIONS   #\u8bbe\u7f6ePCRE\u7684\u989d\u5916\u7f16\u8bd1\u9009\u9879\u3002\r\n--with-md5=DIR            #\u4f7f\u7528MD5\u6c47\u7f16\u6e90\u7801\u3002\r\n--with-md5-opt=OPTIONS    #Set additional options for md5 building.\r\n--with-md5-asm            #Use md5 assembler sources.\r\n--with-sha1=DIR           #Set path to sha1 library sources.\r\n--with-sha1-opt=OPTIONS   #Set additional options for sha1 building.\r\n--with-sha1-asm           #Use sha1 assembler sources.\r\n--with-zlib=DIR           #Set path to zlib library sources.\r\n--with-zlib-opt=OPTIONS   #Set additional options for zlib building.\r\n--with-zlib-asm=CPU       #Use zlib assembler sources optimized for specified CPU, valid values are: pentium, pentiumpro\r\n--with-openssl=DIR        #Set path to OpenSSL library sources\r\n--with-openssl-opt=OPTIONS #Set additional options for OpenSSL building\r\n--with-debug              #\u542f\u7528\u8c03\u8bd5\u65e5\u5fd7\r\n--add-module=PATH         #Add in a third-party module found in directory PATH<\/pre>\n
    \u542f\u52a8nginx<\/strong><\/span><\/div>\n
    [root@linuxprobe nginx-1.10.1]# \/usr\/local\/nginx\/sbin\/nginx\r\n[root@linuxprobe nginx-1.10.1]# netstat -antup | grep nginx\r\ntcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 52553\/nginx<\/pre>\n

    \u6d4b\u8bd5\u662f\u5426\u9690\u85cf\u4e86\u7248\u672c\u548c\u8f6f\u4ef6\u540d<\/strong><\/p>\n

    [root@linuxprobe nginx-1.10.1]# cd\r\n[root@linuxprobe ~]# curl -I http:\/\/127.0.0.1\r\n<\/pre>\n

    \"9-07-01\"<\/p>\n

    \u9519\u8bef\u4ee3\u7801\u6d4b\u8bd5\uff08\u5c3d\u91cf\u4f7f\u7528firefox\u6216\u8005\u7c7b360\u6d4f\u89c8\u5668\uff09<\/p>\n

    \"9-07-02\" Nginx\u8fd0\u884c\u7528\u6237<\/strong><\/p>\n

    [root@linuxprobe~]# useradd -M -s \/sbin\/nologin nginx \/\/\u4fee\u6539nginx\u9ed8\u8ba4\u8fd0\u884c\u7528\u6237\r\n[root@linuxprobe ~]# ps -aux | grep nginx \/\/\u9ed8\u8ba4\u662fnobody\u7528\u6237\r\nnobody 52554 0.0 0.1 22660 1568 ? S 14:39 0:00 nginx: worker process\r\n[root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\nuser nginx;\r\n[root@linuxprobe ~]# \/usr\/local\/nginx\/sbin\/nginx -s reload\r\n[root@linuxprobe ~]# ps -aux | grep nginx\r\nnginx 52555 0.0 0.1 22660 1568 ? S 14:39 0:00 nginx: worker process<\/pre>\n

    \u5728\u8fd9\u91cc\u6211\u4eec\u8fd8\u53ef\u4ee5\u770b\u5230\u5728\u67e5\u770b\u7684\u65f6\u5019\uff0cwork\u8fdb\u7a0b\u662fnginx\u7528\u6237\u4e86\uff0c\u4f46\u662fmaster\u8fdb\u7a0b\u8fd8\u662froot<\/p>\n

    \u5176\u4e2d\uff0cmaster\u662f\u76d1\u63a7\u8fdb\u7a0b\uff0c\u4e5f\u53eb\u4e3b\u8fdb\u7a0b\uff0cwork\u662f\u5de5\u4f5c\u8fdb\u7a0b\uff0c\u90e8\u5206\u8fd8\u6709cache\u76f8\u5173\u8fdb\u7a0b\uff0c\u5173\u7cfb\u5982\u56fe\uff1a<\/p>\n

    \"9-07-03\"<\/a><\/p>\n

    \u6240\u4ee5\u6211\u4eec\u53ef\u4ee5master\u76d1\u63a7\u8fdb\u7a0b\u4f7f\u7528root\uff0c\u53ef\u4ee5\u662f\u964d\u7ea7\u4f7f\u7528\u666e\u901a\u7528\u6237\uff0c\u5982\u679c\u90fd\u662f\u7528\u666e\u7528\u6237\uff0c\u6ce8\u610f\u7f16\u8bd1\u5b89\u88c5\u7684\u65f6\u5019\uff0c\u662f\u7528\u666e\u901a\u7528\u6237\u6267\u884c\uff0csudo\u65b9\u5f0f\u64cd\u4f5c\uff01\u53ef\u4ee5\u76f4\u63a5\u7406\u89e3\u4e3amaster\u662f\u7ba1\u7406\u5458\uff0cwork\u8fdb\u7a0b\u624d\u662f\u4e3a\u7528\u6237\u63d0\u4f9b\u670d\u52a1\u7684\uff01<\/p>\n

    Nginx\u8fd0\u884c\u8fdb\u7a0b\u4e2a\u6570\uff0c\u4e00\u822c\u6211\u4eec\u8bbe\u7f6eCPU\u7684\u6838\u5fc3\u6216\u8005\u6838\u5fc3\u6570x2,\u5982\u679c\u4f60\u4e0d\u4e86\u89e3\uff0ctop\u547d\u4ee4\u4e4b\u540e\u63091\u4e5f\u53ef\u4ee5\u770b\u51fa\u6765\uff08\u4e00\u822c\u76f4\u63a5\u8ffd\u5230\u7ebf\u7a0b\u5373\u53ef\uff09<\/p>\n

    [root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\nworker_processes 2;\r\n[root@linuxprobe ~]# \/usr\/local\/nginx\/sbin\/nginx -s reload\r\n[root@linuxprobe ~]# ps -axu | grep nginx\r\nnginx 52686 0.0 0.1 22668 1300 ? S 15:10 0:00 nginx: worker process\r\nnginx 52687 0.0 0.1 22668 1376 ? S 15:10 0:00 nginx: worker process<\/pre>\n

    Nginx\u8fd0\u884cCPU\u4eb2\u548c\u529b<\/strong>\uff08\u8fd9\u4e2a\u8981\u6839\u636e\u4f60\u7684CPU\u7ebf\u7a0b\u6570\u914d\u7f6e\uff09<\/p>\n

    \u6bd4\u59824\u68384\u7ebf\u7a0b\u914d\u7f6e<\/p>\n

    [root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\nworker_processes 4;\r\nworker_cpu_affinity 0001 0010 0100 1000;<\/pre>\n

    \u6bd4\u59828\u68388\u7ebf\u7a0b\u914d\u7f6e<\/p>\n

    worker_processes 8;\r\nworker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;<\/pre>\n

    \u90a3\u4e48\u5982\u679c\u6211\u662f4\u7ebf\u7a0b\u7684CPU\uff0c\u6211\u53ea\u60f3\u8dd1\u4e24\u4e2a\u8fdb\u7a0b\u5462\uff1f<\/p>\n

    worker_processes 2;\r\nworker_cpu_affinity 0101 1010;<\/pre>\n

    \u610f\u601d\u5c31\u4f3c\u4e4e\u6211\u5f00\u542f\u4e86\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e09\u4e2a\u5185\u6838\uff0c\u7b2c\u4e8c\u4e2a\u548c\u7b2c\u56db\u4e2a\u5185\u6838\uff0c\u4e24\u4e2a\u8fdb\u7a0b\u5206\u522b\u5728\u8fd9\u4e24\u4e2a\u7ec4\u5408\u4e0a\u8f6e\u8be2\uff01worker_processes\u6700\u591a\u5f00\u542f8\u4e2a\uff0c8\u4e2a\u4ee5\u4e0a\u6027\u80fd\u63d0\u5347\u4e0d\u4f1a\u518d\u63d0\u5347\u4e86\uff0c\u800c\u4e14\u7a33\u5b9a\u6027\u53d8\u5f97\u66f4\u4f4e\uff0c\u6240\u4ee58\u4e2a\u8fdb\u7a0b\u591f\u7528\u4e86\u3002<\/p>\n

    Nginx\u6700\u591a\u53ef\u4ee5\u6253\u5f00\u6587\u4ef6\u6570 worker_rlimit_nofile 65535;<\/p>\n

    \u8fd9\u4e2a\u6307\u4ee4\u662f\u6307\u5f53\u4e00\u4e2anginx\u8fdb\u7a0b\u6253\u5f00\u7684\u6700\u591a\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u76ee\uff0c\u7406\u8bba\u503c\u5e94\u8be5\u662f\u6700\u591a\u6253\u5f00\u6587\u4ef6\u6570\uff08ulimit -n\uff09\u4e0enginx\u8fdb\u7a0b\u6570\u76f8\u9664\uff0c\u4f46\u662fnginx\u5206\u914d\u8bf7\u6c42\u5e76\u4e0d\u662f\u90a3\u4e48\u5747\u5300\uff0c\u6240\u4ee5\u6700\u597d\u4e0eulimit -n\u7684\u503c\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n

    Nginx\u4e8b\u4ef6\u5904\u7406\u6a21\u578b<\/p>\n

    events {\r\nuse epoll;\r\nworker_connections 1024;\r\n}<\/pre>\n

    \u77e5\u9053\u5728linux\u4e0bnginx\u91c7\u7528epoll\u4e8b\u4ef6\u6a21\u578b\uff0c\u5904\u7406\u6548\u7387\u9ad8\uff0c\u5173\u4e8eepoll\u7684\u65f6\u95f4\u5904\u7406\u5176\u4ed6\u53ea\u662f\uff0c\u53ef\u4ee5\u81ea\u884c\u767e\u5ea6\uff0c\u4e86\u89e3\u5373\u53ef\uff01<\/p>\n

    Work_connections\u662f\u5355\u4e2a\u8fdb\u7a0b\u5141\u8bb8\u5ba2\u6237\u7aef\u6700\u5927\u8fde\u63a5\u6570\uff0c\u8fd9\u4e2a\u6570\u503c\u4e00\u822c\u6839\u636e\u670d\u52a1\u5668\u6027\u80fd\u548c\u5185\u5b58\u6765\u5236\u5b9a\uff0c\u4e5f\u5c31\u662f\u5355\u4e2a\u8fdb\u7a0b\u6700\u5927\u8fde\u63a5\u6570\uff0c\u5b9e\u9645\u6700\u5927\u503c\u5c31\u662fwork\u8fdb\u7a0b\u6570\u4e58\u4ee5\u8fd9\u4e2a\u6570\uff0c\u5982\u4f55\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u6839\u636e\u8bbe\u7f6e\u4e00\u4e2a\u8fdb\u7a0b\u542f\u52a8\u6240\u5360\u5185\u5b58\uff0ctop -u nginx\uff0c\u4f46\u662f\u5b9e\u9645\u6211\u4eec\u586b\u5165\u4e00\u4e2a65535\uff0c\u8db3\u591f\u4e86\uff0c\u8fd9\u4e9b\u90fd\u7b97\u5e76\u53d1\u503c\uff0c\u4e00\u4e2a\u7f51\u7ad9\u7684\u5e76\u53d1\u8fbe\u5230\u8fd9\u4e48\u5927\u7684\u6570\u91cf\uff0c\u4e5f\u7b97\u4e00\u4e2a\u5927\u7ad9\u4e86\uff01<\/p>\n

    \u5f00\u542f\u9ad8\u6548\u4f20\u8f93\u6a21\u5f0f<\/p>\n

    http {\r\n\r\ninclude mime.types;\r\ndefault_type application\/octet-stream;\r\n\u2026\u2026\r\nsendfile on;\r\n#tcp_nopush on;\r\n\u2026\u2026\r\n Include mime.types;   \u5a92\u4f53\u7c7b\u578b\r\n default_type application\/octet-stream;   \u9ed8\u8ba4\u5a92\u4f53\u7c7b\u578b\u8db3\u591f\r\n sendfile on\uff1b   \u5f00\u542f\u9ad8\u6548\u6587\u4ef6\u4f20\u8f93\u6a21\u5f0f\uff0csendfile\u6307\u4ee4\u6307\u5b9anginx\u662f\u5426\u8c03\u7528sendfile\u51fd\u6570\u6765\u8f93\u51fa\u6587\u4ef6\uff0c\u5bf9\u4e8e\u666e\u901a\u5e94\u7528\u8bbe\u4e3a on\uff0c\u5982\u679c\u7528\u6765\u8fdb\u884c\u4e0b\u8f7d\u7b49\u5e94\u7528\u78c1\u76d8IO\u91cd\u8d1f\u8f7d\u5e94\u7528\uff0c\u53ef\u8bbe\u7f6e\u4e3aoff\uff0c\u4ee5\u5e73\u8861\u78c1\u76d8\u4e0e\u7f51\u7edcI\/O\u5904\u7406\u901f\u5ea6\uff0c\u964d\u4f4e\u7cfb\u7edf\u7684\u8d1f\u8f7d\u3002\u6ce8\u610f\uff1a\u5982\u679c\u56fe\u7247\u663e\u793a\u4e0d\u6b63\u5e38\u628a\u8fd9\u4e2a\u6539\u6210off\u3002\r\n tcp_nopush on\uff1b   \u5fc5\u987b\u5728sendfile\u5f00\u542f\u6a21\u5f0f\u624d\u6709\u6548\uff0c\u9632\u6b62\u7f51\u8def\u963b\u585e\uff0c\u79ef\u6781\u7684\u51cf\u5c11\u7f51\u7edc\u62a5\u6587\u6bb5\u7684\u6570\u91cf<\/pre>\n

    \u8fde\u63a5\u8d85\u65f6\u65f6\u95f4<\/strong><\/p>\n

    \u4e3b\u8981\u76ee\u7684\u662f\u4fdd\u62a4\u670d\u52a1\u5668\u8d44\u6e90\uff0cCPU\uff0c\u5185\u5b58\uff0c\u63a7\u5236\u8fde\u63a5\u6570\uff0c\u56e0\u4e3a\u5efa\u7acb\u8fde\u63a5\u4e5f\u662f\u9700\u8981\u6d88\u8017\u8d44\u6e90\u7684\uff0cTCP\u7684\u4e09\u6b21\u63e1\u624b\u56db\u6b21\u6325\u624b\u7b49\uff0c\u6211\u4eec\u4e00\u822c\u65ad\u6389\u7684\u662f\u90a3\u4e9b\u5efa\u7acb\u8fde\u63a5\u4f46\u662f\u4e0d\u505a\u4e8b\u513f\uff0c\u4e5f\u5c31\u662f\u6211\u5efa\u7acb\u4e86\u94fe\u63a5\u5f00\u59cb\uff0c\u4f46\u662f\u540e\u7eed\u7684\u63e1\u624b\u8fc7\u7a0b\u6ca1\u6709\u8fdb\u884c\uff0c\u90a3\u4e48\u6211\u4eec\u7684\u94fe\u63a5\u5904\u4e8e\u7b49\u5f85\u72b6\u6001\u7684\uff0c\u5168\u90e8\u65ad\u6389\uff01<\/p>\n

    \u540c\u65f6\u6211\u4eec\u4e5f\u5e0c\u671bphp\u5efa\u8bae\u77ed\u94fe\u63a5\uff0c\u6d88\u8017\u8d44\u6e90\u5c11<\/p>\n

    Java\u5efa\u8bae\u957f\u94fe\u63a5\uff0c\u6d88\u8017\u8d44\u6e90\u5c11<\/p>\n

    keepalive_timeout 60;\r\ntcp_nodelay on;\r\nclient_header_timeout 15;\r\nclient_body_timeout 15;\r\nsend_timeout 15;\r\nkeepalived_timeout \u5ba2\u6237\u7aef\u8fde\u63a5\u4fdd\u6301\u4f1a\u8bdd\u8d85\u65f6\u65f6\u95f4\uff0c\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\uff0c\u670d\u52a1\u5668\u65ad\u5f00\u8fd9\u4e2a\u94fe\u63a5\r\ntcp_nodelay\uff1b\u4e5f\u662f\u9632\u6b62\u7f51\u7edc\u963b\u585e\uff0c\u4e0d\u8fc7\u8981\u5305\u6db5\u5728keepalived\u53c2\u6570\u624d\u6709\u6548\r\nclient_header_timeout \u5ba2\u6237\u7aef\u8bf7\u6c42\u5934\u8bfb\u53d6\u8d85\u65f6\u65f6\u95f4\uff0c\u5982\u679c\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\u6ca1\u6709\u53d1\u9001\u4efb\u4f55\u6570\u636e\uff0cnginx\u5c06\u8fd4\u56derequest time out\u7684\u9519\u8bef\r\nclient_body_timeout \u5ba2\u6237\u7aef\u6c42\u4e3b\u4f53\u8d85\u65f6\u65f6\u95f4\uff0c\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\u6ca1\u6709\u53d1\u9001\u4efb\u4f55\u6570\u636e\uff0c\u548c\u4e0a\u9762\u4e00\u6837\u7684\u9519\u8bef\u63d0\u793a\r\nsend_timeout \u54cd\u5e94\u5ba2\u6237\u7aef\u8d85\u65f6\u65f6\u95f4\uff0c\u8fd9\u4e2a\u8d85\u65f6\u65f6\u95f4\u4ec5\u9650\u4e8e\u4e24\u4e2a\u6d3b\u52a8\u4e4b\u95f4\u7684\u65f6\u95f4\uff0c\u5982\u679c\u8d85\u54e5\u8fd9\u4e2a\u65f6\u95f4\uff0c\u5ba2\u6237\u7aef\u6ca1\u6709\u4efb\u4f55\u6d3b\u52a8\uff0cnginx\u5173\u95ed\u8fde\u63a5<\/pre>\n

    \u6587\u4ef6\u4e0a\u4f20\u5927\u5c0f\u9650\u5236<\/strong><\/p>\n

    \u6211\u4eec\u77e5\u9053PHP\u53ef\u4ee5\u4fee\u6539\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u9650\u5236\uff0cnginx\u4e5f\u53ef\u4ee5\u4fee\u6539<\/p>\n

    http {\r\n\u2026\u2026\r\nclient_max_body_size 10m;<\/pre>\n
    Fastcgi\u8c03\u4f18<\/strong><\/span><\/div>\n

    Nginx\u6ca1\u6709\u914d\u7f6efactcgi\uff0c\u4f60\u4f7f\u7528nginx\u662f\u4e00\u4e2a\u5931\u8d25\u7684\u65b9\u6cd5\uff0c\u914d\u7f6e\u4e4b\u524d\u3002\u4e86\u89e3\u51e0\u4e2a\u6982\u5ff5\uff1a<\/p>\n

    \r\nCache\uff1a  \u5199\u5165\u7f13\u5b58\u533a\r\nBuffer\uff1a \u8bfb\u53d6\u7f13\u5b58\u533a\r\nFastcgi  \u662f\u9759\u6001\u670d\u52a1\u548c\u52a8\u6001\u670d\u52a1\u7684\u4e00\u4e2a\u63a5\u53e3\r\nfastcgi_connect_timeout 300;     #\u6307\u5b9a\u94fe\u63a5\u5230\u540e\u7aefFastCGI\u7684\u8d85\u65f6\u65f6\u95f4\u3002\r\nfastcgi_send_timeout 300;        #\u5411FastCGI\u4f20\u9001\u8bf7\u6c42\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u8fd9\u4e2a\u503c\u662f\u6307\u5df2\u7ecf\u5b8c\u6210\u4e24\u6b21\u63e1\u624b\u540e\u5411FastCGI\u4f20\u9001\u8bf7\u6c42\u7684\u8d85\u65f6\u65f6\u95f4\u3002\r\nfastcgi_read_timeout 300;        #\u6307\u5b9a\u63a5\u6536FastCGI\u5e94\u7b54\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u8fd9\u4e2a\u503c\u662f\u6307\u5df2\u7ecf\u5b8c\u6210\u4e24\u6b21\u63e1\u624b\u540e\u63a5\u6536FastCGI\u5e94\u7b54\u7684\u8d85\u65f6\u65f6\u95f4\u3002\r\nfastcgi_buffer_size 64k;         #\u6307\u5b9a\u8bfb\u53d6FastCGI\u5e94\u7b54\u7b2c\u4e00\u90e8\u5206\u9700\u8981\u7528\u591a\u5927\u7684\u7f13\u51b2\u533a\uff0c\u8fd9\u4e2a\u503c\u8868\u793a\u5c06\u4f7f\u75281\u4e2a64KB\u7684\u7f13\u51b2\u533a\u8bfb\u53d6\u5e94\u7b54\u7684\u7b2c\u4e00\u90e8\u5206\uff08\u5e94\u7b54\u5934\uff09\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3agastcgi_buffers\u9009\u9879\u6307\u5b9a\u7684\u7f13\u51b2\u533a\u5927\u5c0f\u3002\r\nfastcgi_buffers 4 64k;          #\u6307\u5b9a\u672c\u5730\u9700\u8981\u7528\u591a\u5c11\u548c\u591a\u5927\u7684\u7f13\u51b2\u533a\u6765\u7f13\u51b2FastCGI\u7684\u5e94\u7b54\u8bf7\u6c42\uff0c\u5982\u679c\u4e00\u4e2aphp\u811a\u672c\u6240\u4ea7\u751f\u7684\u9875\u9762\u5927\u5c0f\u4e3a256KB\uff0c\u90a3\u4e48\u4f1a\u5206\u914d4\u4e2a64KB\u7684\u7f13\u51b2\u533a\u6765\u7f13\u5b58\uff0c\u5982\u679c\u9875\u9762\u5927\u5c0f\u5927\u4e8e256KB\uff0c\u90a3\u4e48\u5927\u4e8e256KB\u7684\u90e8\u5206\u4f1a\u7f13\u5b58\u5230fastcgi_temp\u6307\u5b9a\u7684\u8def\u5f84\u4e2d\uff0c\u4f46\u662f\u8fd9\u5e76\u4e0d\u662f\u597d\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5185\u5b58\u4e2d\u7684\u6570\u636e\u5904\u7406\u901f\u5ea6\u8981\u5feb\u4e8e\u78c1\u76d8\u3002\u4e00\u822c\u8fd9\u4e2a\u503c\u5e94\u8be5\u4e3a\u7ad9\u70b9\u4e2dphp\u811a\u672c\u6240\u4ea7\u751f\u7684\u9875\u9762\u5927\u5c0f\u7684\u4e2d\u95f4\u503c\uff0c\u5982\u679c\u7ad9\u70b9\u5927\u90e8\u5206\u811a\u672c\u6240\u4ea7\u751f\u7684\u9875\u9762\u5927\u5c0f\u4e3a256KB\uff0c\u90a3\u4e48\u53ef\u4ee5\u628a\u8fd9\u4e2a\u503c\u8bbe\u7f6e\u4e3a\u201c8 16K\u201d\u3001\u201c4 64k\u201d\u7b49\u3002\r\nfastcgi_busy_buffers_size 128k;      #\u5efa\u8bae\u8bbe\u7f6e\u4e3afastcgi_buffer\u7684\u4e24\u500d\uff0c\u7e41\u5fd9\u65f6\u5019\u7684buffer\r\nfastcgi_temp_file_write_size 128k;   #\u5728\u5199\u5165fastcgi_temp_path\u65f6\u5c06\u7528\u591a\u5927\u7684\u6570\u636e\u5e93\uff0c\u9ed8\u8ba4\u503c\u662ffastcgi_buffers\u7684\u4e24\u500d\uff0c\u8bbe\u7f6e\u4e0a\u8ff0\u6570\u503c\u8bbe\u7f6e\u5c0f\u65f6\u82e5\u8d1f\u8f7d\u4e0a\u6765\u65f6\u53ef\u80fd\u62a5502Bad Gateway\r\nfastcgi_cache aniu_ngnix;        #\u8868\u793a\u5f00\u542fFastCGI\u7f13\u5b58\u5e76\u4e3a\u5176\u6307\u5b9a\u4e00\u4e2a\u540d\u79f0\u3002\u5f00\u542f\u7f13\u5b58\u975e\u5e38\u6709\u7528\uff0c\u53ef\u4ee5\u6709\u6548\u964d\u4f4eCPU\u7684\u8d1f\u8f7d\uff0c\u5e76\u4e14\u9632\u6b62502\u7684\u9519\u8bef\u653e\u751f\uff0c\u4f46\u662f\u5f00\u542f\u7f13\u5b58\u4e5f\u53ef\u80fd\u4f1a\u5f15\u8d77\u5176\u4ed6\u95ee\u9898\uff0c\u8981\u5f88\u636e\u5177\u4f53\u60c5\u51b5\u9009\u62e9\r\nfastcgi_cache_valid 200 302 1h;  #\u7528\u6765\u6307\u5b9a\u5e94\u7b54\u4ee3\u7801\u7684\u7f13\u5b58\u65f6\u95f4\uff0c\u5b9e\u4f8b\u4e2d\u7684\u503c\u8868\u793a\u5c062000\u548c302\u5e94\u7b54\u7f13\u5b58\u4e00\u5c0f\u65f6\uff0c\u8981\u548cfastcgi_cache\u914d\u5408\u4f7f\u7528\r\nfastcgi_cache_valid 301 1d;      #\u5c06301\u5e94\u7b54\u7f13\u5b58\u4e00\u5929\r\nfastcgi_cache_valid any 1m;      #\u5c06\u5176\u4ed6\u5e94\u7b54\u7f13\u5b58\u4e3a1\u5206\u949f\r\nfastcgi_cache_min_uses 1;        #\u8bf7\u6c42\u7684\u6570\u91cf\r\nfastcgi_cache_path               #\u5b9a\u4e49\u7f13\u5b58\u7684\u8def\u5f84<\/pre>\n

    \u4fee\u6539nginx.conf\u914d\u7f6e\u6587\u4ef6\uff0c\u5728http\u6807\u7b7e\u4e2d\u6dfb\u52a0\u5982\u4e0b\uff1a<\/p>\n

    fastcgi_connect_timeout 300;\r\nfastcgi_send_timeout 300;\r\nfastcgi_read_timeout 300;\r\nfastcgi_buffer_size 64k;\r\nfastcgi_buffers 4 64k;\r\nfastcgi_busy_buffers_size 128k;\r\nfastcgi_temp_file_write_size 128k;\r\n#fastcgi_temp_path \/data\/ngx_fcgi_tmp;\r\nfastcgi_cache_path \/opt\/ngx_fcgi_cache levels=2:2\r\nkeys_zone=ngx_fcgi_cache:512m\r\ninactive=1d max_size=40g;<\/pre>\n

    \u7f13\u5b58\u8def\u5f84\uff0clevels\u76ee\u5f55\u5c42\u6b212\u7ea7\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5b58\u50a8\u533a\u57df\u540d\u5b57\uff0c\u7f13\u5b58\u5927\u5c0f\uff0c\u4e0d\u6d3b\u52a8\u7684\u6570\u636e\u5728\u7f13\u5b58\u4e2d\u591a\u957f\u65f6\u95f4\uff0c\u76ee\u5f55\u603b\u5927\u5c0f<\/p>\n

    \u5728server location\u6807\u7b7e\u6dfb\u52a0\u5982\u4e0b\uff1a<\/p>\n

    location ~ .*\\.(php|php5)?$\r\n{\r\nfastcgi_pass 127.0.0.1:9000;\r\nfastcgi_index index.php;\r\ninclude fastcgi.conf;\r\nfastcgi_cache ngx_fcgi_cache;\r\nfastcgi_cache_valid 200 302 1h;\r\nfastcgi_cache_valid 301 1d;\r\nfastcgi_cache_valid any 1m;\r\nfastcgi_cache_min_uses 1;\r\nfastcgi_cache_use_stale error timeout invalid_header http_500;\r\nfastcgi_cache_key http:\/\/$host$request_uri;\r\n}<\/pre>\n

    fastcgi cache\u5b98\u65b9\u6587\u6863\uff1ahttp:\/\/nginx.org\/en\/docs\/http\/ngx_http_fastcgi_module.html#fastcgi_cache<\/p>\n

    gzip\u8c03\u4f18<\/strong><\/span><\/div>\n

    \u4f7f\u7528gzip\u538b\u7f29\u529f\u80fd\uff0c\u53ef\u80fd\u4e3a\u6211\u4eec\u8282\u7ea6\u5e26\u5bbd\uff0c\u52a0\u5feb\u4f20\u8f93\u901f\u5ea6\uff0c\u6709\u66f4\u597d\u7684\u4f53\u9a8c\uff0c\u4e5f\u4e3a\u6211\u4eec\u8282\u7ea6\u6210\u672c\uff0c\u6240\u4ee5\u8bf4\u8fd9\u662f\u4e00\u4e2a\u91cd\u70b9<\/p>\n

    Nginx\u542f\u7528\u538b\u7f29\u529f\u80fd\u9700\u8981\u4f60\u6765ngx_http_gzip_module\u6a21\u5757\uff0capache\u4f7f\u7528\u7684\u662fmod_deflate<\/p>\n

    \u4e00\u822c\u6211\u4eec\u9700\u8981\u538b\u7f29\u7684\u5185\u5bb9\u6709\uff1a\u6587\u672c\uff0cjs\uff0chtml\uff0ccss\uff0c\u5bf9\u4e8e\u56fe\u7247\uff0c\u89c6\u9891\uff0cflash\u4ec0\u4e48\u7684\u4e0d\u538b\u7f29\uff0c\u540c\u65f6\u4e5f\u8981\u6ce8\u610f\uff0c\u6211\u4eec\u4f7f\u7528gzip\u7684\u529f\u80fd\u662f\u9700\u8981\u6d88\u8017CPU\u7684\uff01<\/p>\n

    gzip on;     #\u5f00\u542f\u538b\u7f29\u529f\u80fd\r\ngzip_min_length 1k;    #\u8bbe\u7f6e\u5141\u8bb8\u538b\u7f29\u7684\u9875\u9762\u6700\u5c0f\u5b57\u8282\u6570\uff0c\u9875\u9762\u5b57\u8282\u6570\u4eceheader\u5934\u7684Content-Length\u4e2d\u83b7\u53d6\uff0c\u9ed8\u8ba4\u503c\u662f0\uff0c\u4e0d\u7ba1\u9875\u9762\u591a\u5927\u90fd\u8fdb\u884c\u538b\u7f29\uff0c\u5efa\u8bae\u8bbe\u7f6e\u6210\u5927\u4e8e1K\uff0c\u5982\u679c\u5c0f\u4e0e1K\u53ef\u80fd\u4f1a\u8d8a\u538b\u8d8a\u5927\u3002\r\ngzip_buffers 4 32k;        #\u538b\u7f29\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u8868\u793a\u7533\u8bf74\u4e2a\u5355\u4f4d\u4e3a32K\u7684\u5185\u5b58\u4f5c\u4e3a\u538b\u7f29\u7ed3\u679c\u6d41\u7f13\u5b58\uff0c\u9ed8\u8ba4\u503c\u662f\u7533\u8bf7\u4e0e\u539f\u59cb\u6570\u636e\u5927\u5c0f\u76f8\u540c\u7684\u5185\u5b58\u7a7a\u95f4\u6765\u5b58\u50a8gzip\u538b\u7f29\u7ed3\u679c\u3002\r\ngzip_http_version 1.1;     #\u538b\u7f29\u7248\u672c\uff08\u9ed8\u8ba41.1\uff0c\u524d\u7aef\u4e3asquid2.5\u65f6\u4f7f\u75281.0\uff09\u7528\u4e8e\u8bbe\u7f6e\u8bc6\u522bHTTP\u534f\u8bae\u7248\u672c\uff0c\u9ed8\u8ba4\u662f1.1\uff0c\u76ee\u524d\u5927\u90e8\u5206\u6d4f\u89c8\u5668\u5df2\u7ecf\u652f\u6301GZIP\u89e3\u538b\uff0c\u4f7f\u7528\u9ed8\u8ba4\u5373\u53ef\r\ngzip_comp_level 9;         #\u538b\u7f29\u6bd4\u4f8b\uff0c\u7528\u6765\u6307\u5b9aGZIP\u538b\u7f29\u6bd4\uff0c1\u538b\u7f29\u6bd4\u6700\u5c0f\uff0c\u5904\u7406\u901f\u5ea6\u6700\u5feb\uff0c9\u538b\u7f29\u6bd4\u6700\u5927\uff0c\u4f20\u8f93\u901f\u5ea6\u5feb\uff0c\u4f46\u662f\u5904\u7406\u6162\uff0c\u4e5f\u6bd4\u8f83\u6d88\u8017CPU\u8d44\u6e90\u3002\r\ngzip_types text\/css text\/xml application\/javascript;      #\u7528\u6765\u6307\u5b9a\u538b\u7f29\u7684\u7c7b\u578b\uff0c\u2018text\/html\u2019\u7c7b\u578b\u603b\u662f\u4f1a\u88ab\u538b\u7f29\u3002\r\ngzip_vary on;        #vary header\u652f\u6301\uff0c\u6539\u9009\u9879\u53ef\u4ee5\u8ba9\u524d\u7aef\u7684\u7f13\u5b58\u670d\u52a1\u5668\u7f13\u5b58\u7ecf\u8fc7GZIP\u538b\u7f29\u7684\u9875\u9762\uff0c\u4f8b\u5982\u7528Squid\u7f13\u5b58\u7ecf\u8fc7nginx\u538b\u7f29\u7684\u6570\u636e<\/pre>\n

    \u90a3\u4e48\u914d\u7f6e\u538b\u7f29\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u6709\u4e00\u4e0b\u53c2\u6570<\/p>\n

    gzip on;\r\ngzip_min_length 1k;\r\ngzip_buffers 4 32k;\r\ngzip_http_version 1.1;\r\ngzip_comp_level 9;\r\ngzip_types text\/plain application\/javascript application\/x-javascript text\/javascript text\/css application\/xml application\/xml+rss;\r\ngzip_vary on;\r\ngzip_proxied expired no-cache no-store private auth;\r\ngzip_disable \"MSIE [1-6]\\.\";<\/pre>\n
    expires\u7f13\u5b58\u8c03\u4f18<\/strong><\/span><\/div>\n

    \u7f13\u5b58\uff0c\u4e3b\u8981\u9488\u5bf9\u4e8e\u56fe\u7247\uff0ccss\uff0cjs\u7b49\u5143\u7d20\u66f4\u6539\u673a\u4f1a\u6bd4\u8f83\u5c11\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\uff0c\u7279\u522b\u662f\u56fe\u7247\uff0c\u5360\u7528\u5e26\u5bbd\u5927\uff0c\u6211\u4eec\u5b8c\u5168\u53ef\u4ee5\u8bbe\u7f6e\u56fe\u7247\u5728\u6d4f\u89c8\u5668\u672c\u5730\u7f13\u5b58365d\uff0ccss\uff0cjs\uff0chtml\u53ef\u4ee5\u7f13\u5b58\u4e2a10\u6765\u5929\uff0c\u8fd9\u6837\u7528\u6237\u7b2c\u4e00\u6b21\u6253\u5f00\u52a0\u8f7d\u6162\u4e00\u70b9\uff0c\u7b2c\u4e8c\u6b21\uff0c\u5c31\u975e\u5e38\u5feb\u4e50\uff01\u7f13\u5b58\u7684\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u5c06\u9700\u8981\u7f13\u5b58\u7684\u62d3\u5c55\u540d\u5217\u51fa\u6765\uff01<\/p>\n

    Expires\u7f13\u5b58\u914d\u7f6e\u5728server\u5b57\u6bb5\u91cc\u9762<\/p>\n

    location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$\r\n{\r\nexpires 3650d;\r\n}\r\nlocation ~ .*\\.(js|css)?$\r\n{\r\nexpires 30d;\r\n}<\/pre>\n

    \u540c\u65f6\u4e5f\u53ef\u4ee5\u5bf9\u76ee\u5f55\u53ca\u5176\u8fdb\u884c\u5224\u65ad\uff1a<\/p>\n

    location ~ ^\/(images|javascript|js|css|flash|media|static)\/ {\r\nexpires 360d;\r\n}\r\nlocation ~(robots.txt) {\r\nexpires 7d;\r\nbreak;\r\n}<\/pre>\n

    expire\u529f\u80fd\u4f18\u70b9<\/strong>
    \n\uff081\uff09expires\u53ef\u4ee5\u964d\u4f4e\u7f51\u7ad9\u8d2d\u4e70\u7684\u5e26\u5bbd\uff0c\u8282\u7ea6\u6210\u672c
    \n\uff082\uff09\u540c\u65f6\u63d0\u5347\u7528\u6237\u8bbf\u95ee\u4f53\u9a8c
    \n\uff083\uff09\u51cf\u8f7b\u670d\u52a1\u7684\u538b\u529b\uff0c\u8282\u7ea6\u670d\u52a1\u5668\u6210\u672c\uff0c\u751a\u81f3\u53ef\u4ee5\u8282\u7ea6\u4eba\u529b\u6210\u672c\uff0c\u662fweb\u670d\u52a1\u975e\u5e38\u91cd\u8981\u7684\u529f\u80fd\u3002<\/p>\n

    expire\u529f\u80fd\u7f3a\u70b9\uff1a<\/p>\n

    \u88ab\u7f13\u5b58\u7684\u9875\u9762\u6216\u6570\u636e\u66f4\u65b0\u4e86\uff0c\u7528\u6237\u770b\u5230\u7684\u53ef\u80fd\u8fd8\u662f\u65e7\u7684\u5185\u5bb9\uff0c\u53cd\u800c\u5f71\u54cd\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n

    \u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n

    \u7b2c\u4e00\u4e2a \u7f29\u77ed\u7f13\u5b58\u65f6\u95f4\uff0c\u4f8b\u5982\uff1a1\u5929\uff0c\u4e0d\u5f7b\u5e95\uff0c\u9664\u975e\u66f4\u65b0\u9891\u7387\u5927\u4e8e1\u5929<\/p>\n

    \u7b2c\u4e8c\u4e2a \u5bf9\u7f13\u5b58\u7684\u5bf9\u8c61\u6539\u540d<\/p>\n

    a.\u56fe\u7247\uff0c\u9644\u4ef6\u4e00\u822c\u4e0d\u4f1a\u88ab\u7528\u6237\u4fee\u6539\uff0c\u5982\u679c\u7528\u6237\u4fee\u6539\u4e86\uff0c\u5b9e\u9645\u4e0a\u4e5f\u662f\u66f4\u6539\u6587\u4ef6\u540d\u91cd\u65b0\u4f20\u4e86\u800c\u5df2<\/p>\n

    b.\u7f51\u7ad9\u5347\u7ea7\u5bf9\u4e8ejs\uff0ccss\u5143\u7d20\uff0c\u4e00\u822c\u53ef\u4ee5\u6539\u540d\uff0c\u628acss\uff0cjs\uff0c\u63a8\u9001\u5230CDN\u3002<\/p>\n

    \u7f51\u7ad9\u4e0d\u5e0c\u671b\u88ab\u7f13\u5b58\u7684\u5185\u5bb9<\/p>\n

    1\uff09\u5e7f\u544a\u56fe\u7247<\/p>\n

    2\uff09\u7f51\u7ad9\u6d41\u91cf\u7edf\u8ba1\u5de5\u5177<\/p>\n

    3\uff09\u66f4\u65b0\u9891\u7e41\u7684\u6587\u4ef6\uff08google\u7684logo\uff09<\/p>\n

    [root@linuxprobe ~]# cd \/usr\/local\/nginx\/logs\/<\/pre>\n

    \u65e5\u5fd7\u4f18\u5316\u7684\u76ee\u7684\uff0c\u662f\u4e3a\u4e86\u4e00\u5929\u65e5\u5fd7\u4e00\u538b\u7f29\uff0c\u711a\u5929\u5b58\u653e\uff0c\u8d85\u8fc710\u5929\u7684\u5220\u9664<\/p>\n

    \u521b\u5efa\u65e5\u5fd7\u5207\u5272\u811a\u672c<\/strong><\/span><\/div>\n

    \/\/\u6bcf\u5929\u65e5\u5fd7\u5206\u5272\u811a\u672c<\/p>\n

    [root@linuxprobe logs]# vim cut_nginx_log.sh\r\n#!\/bin\/bash\r\n######################################\r\n#function:cut nginx log files\r\n#author: shaon\r\n######################################\r\n#set the path to nginx log files\r\nlog_files_path=\"\/usr\/local\/nginx\/logs\"\r\nlog_files_dir=${log_files_path}\/$(date -d \"yesterday\" +\"%Y\")\/$(date -d \"yesterday\" +\"%m\")\r\nlog_files_dir=${log_files_path}\/$(date -d \"yesterday\" +\"%Y\")\/$(date -d \"yesterday\" +\"%m\")\r\n#set nginx log files you want to cut\r\nlog_files_name=(access error)\r\n#set the path to nginx.\r\nnginx_sbin=\"\/usr\/local\/nginx\/sbin\/nginx\"\r\n#Set how long you want to save\r\nsave_days=30\r\n############################################\r\n#Please do not modify the following script #\r\n############################################\r\nmkdir -p $log_files_dir\r\nlog_files_num=${#log_files_name[@]}\r\n\r\n#cut nginx log files\r\nfor((i=0;i<$log_files_num;i++));do\r\nmv ${log_files_path}\/${log_files_name[i]}.log ${log_files_dir}\/${log_files_name[i]}_$(date -d \"yesterday\" +\"%Y%m%d\").log\r\ndone ays -exec rm -rf {}\r\n#delete 30 days ago nginx log files\r\nfind $log_files_path -mtime +$save_days -exec rm -rf {} \\;<\/pre>\n

    \u5065\u5eb7\u68c0\u67e5\u7684\u65e5\u5fd7\uff0c\u4e0d\u8f93\u5165\u5230log\u4e2d\uff0c\u8fd9\u4e9b\u65e5\u5fd7\u6ca1\u6709\u610f\u4e49\uff0c\u6211\u4eec\u5206\u6790\u7684\u8bdd\u53ea\u9700\u8981\u5206\u6790\u8bbf\u95ee\u65e5\u5fd7\uff0c\u770b\u770b\u4e00\u4e9b\u9875\u9762\u94fe\u63a5\uff0c\u5982200\uff0c301\uff0c404\u7684\u72b6\u6001\u5417\uff0c\u5728SEO\u4e2d\u5f88\u91cd\u8981\uff0c\u800c\u4e14\u6211\u4eec\u7edf\u8ba1PV\u662f\u9875\u9762\u8ba1\u7b97\uff0c\u8fd9\u4e9b\u90fd\u6ca1\u6709\u610f\u4e49\uff0c\u53cd\u800c\u6d88\u8017\u4e86\u78c1\u76d8IO\uff0c\u964d\u4f4e\u4e86\u670d\u52a1\u5668\u6027\u80fd\uff0c\u6211\u4eec\u53ef\u4ee5\u5c4f\u853d\u8fd9\u4e9b\u5982\u56fe\u7247\uff0cjs\uff0ccss\u8fd9\u4e9b\u4e0d\u5b9c\u53d8\u5316\u7684\u5185\u5bb9<\/p>\n

    [root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\nlocation ~ .*\\.(js|jpg|jpeg|JPG|JPEG|css|bmp|gif|GIF)$ {\r\naccess_log off;\r\n}<\/pre>\n

    \u65e5\u5fd7\u76ee\u5f55\u6743\u9650\u4f18\u5316<\/strong><\/p>\n

    [root@linuxprobe ~]# chown -R root:root \/usr\/local\/nginx\/logs\r\n[root@linuxprobe ~]# chmod 700 \/usr\/local\/nginx\/logs<\/pre>\n

    \u65e5\u5fd7\u683c\u5f0f\u4f18\u5316<\/strong><\/p>\n

    #vim \/usr\/local\/nginx\/conf\/nginx.conf\r\nlog_format access \u2018$remote_addr \u2013 $remote_user [$time_local] \u201c$request\u201d \u2018\u2018$status $body_bytes_sent \u201c$http_referer\u201d \u2018\u2018\u201d$http_user_agent\u201d $http_x_forwarded_for\u2019;<\/pre>\n

    \u5176\u4e2d\uff0c\u5404\u4e2a\u5b57\u6bb5\u7684\u542b\u4e49\u5982\u4e0b\uff1a<\/p>\n

    1.$remote_addr  \u4e0e$http_x_forwarded_for \u7528\u4ee5\u8bb0\u5f55\u5ba2\u6237\u7aef\u7684ip\u5730\u5740\uff1b\r\n2.$remote_user \uff1a    \u7528\u6765\u8bb0\u5f55\u5ba2\u6237\u7aef\u7528\u6237\u540d\u79f0\uff1b\r\n3.$time_local \uff1a     \u7528\u6765\u8bb0\u5f55\u8bbf\u95ee\u65f6\u95f4\u4e0e\u65f6\u533a\uff1b\r\n4.$request \uff1a        \u7528\u6765\u8bb0\u5f55\u8bf7\u6c42\u7684url\u4e0ehttp\u534f\u8bae\uff1b\r\n5.$status \uff1a         \u7528\u6765\u8bb0\u5f55\u8bf7\u6c42\u72b6\u6001\uff1b\u6210\u529f\u662f200\uff0c\r\n6.$body_bytes_s ent \uff1a\u8bb0\u5f55\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u6587\u4ef6\u4e3b\u4f53\u5185\u5bb9\u5927\u5c0f\uff1b\r\n7.$http_referer \uff1a    \u7528\u6765\u8bb0\u5f55\u4ece\u90a3\u4e2a\u9875\u9762\u94fe\u63a5\u8bbf\u95ee\u8fc7\u6765\u7684\uff1b\r\n8.$http_user_agent \uff1a \u8bb0\u5f55\u5ba2\u6237\u7aef\u6d4f\u89c8\u5668\u7684\u76f8\u5173\u4fe1\u606f\uff1b<\/pre>\n

    \u76ee\u5f55\u6587\u4ef6\u8bbf\u95ee\u63a7\u5236<\/strong><\/p>\n

    \u4e3b\u8981\u7528\u5728\u7981\u6b62\u76ee\u5f55\u4e0b\u6307\u5b9a\u6587\u4ef6\u88ab\u8bbf\u95ee\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u7981\u6b62\u6240\u6709\u6587\u4ef6\u88ab\u8bbf\u95ee\uff01\u4e00\u822c\u4ec0\u4e48\u60c5\u51b5\u4e0b\u7528\uff1f\u6bd4\u5982\u662f\u6709\u5b58\u50a8\u5171\u4eab\uff0c\u8fd9\u4e9b\u6587\u4ef6\u672c\u6765\u90fd\u53ea\u662f\u4e00\u4e0b\u8d44\u6e90\u6587\u4ef6\uff0c\u90a3\u4e48\u8fd9\u4e9b\u8d44\u6e90\u6587\u4ef6\u5c31\u4e0d\u5141\u8bb8\u88ab\u6267\u884c\uff0c\u5982sh.py,pl,php\u7b49\u7b49<\/p>\n

    \u4f8b\u5982\uff1a\u7981\u6b62\u8bbf\u95eeimages\u4e0b\u9762\u7684php\u7a0b\u5e8f\u6587\u4ef6<\/p>\n

    location ~ ^\/images\/.*\\.(php|php5|.sh|.py|.py)$ {\r\ndeny all\uff1b\r\n}<\/pre>\n
    [root@linuxprobe ~]# \/usr\/local\/nginx\/sbin\/nginx -s reload\r\n[root@linuxprobe ~]# mkdir \/usr\/local\/nginx\/html\/images\r\n[root@linuxprobe ~]# echo \"\" > \/usr\/local\/nginx\/html\/images\/index.php<\/pre>\n

    \u6d4b\u8bd5\u8bbf\u95ee
    \n\"9-07-04\"<\/p>\n

    \u591a\u76ee\u5f55\u7ec4\u5408\u914d\u7f6e\u65b9\u6cd5<\/strong><\/p>\n

    location ~ ^\/images\/(attachment|avatar)\/.*\\.(php|php5|.sh|.py|.py)$ {\r\ndeny all;\r\n}\r\n<\/pre>\n

    \u914d\u7f6enginx\u7981\u6b62\u8bbf\u95ee*.txt\u6587\u4ef6<\/strong><\/p>\n

    [root@linuxprobe ~]# echo \"hello,linuxprobe\" > \/usr\/local\/nginx\/html\/test.txt\r\n<\/pre>\n

    \"9-07-05\"<\/p>\n

    \u914d\u7f6e\u89c4\u5219\uff0c\u7981\u6b62\u8bbf\u95ee<\/strong><\/p>\n

    [root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf \/\/server\u5b57\u6bb5\u4e2d\r\nlocation ~* \\.(txt|doc)$ {\r\nif ( -f $request_filename) {\r\nroot \/usr\/local\/nginx\/html;\r\nbreak;\r\n}\r\ndeny all;\r\n}\r\n[root@linuxprobe ~]# \/usr\/local\/nginx\/sbin\/nginx -s reload\r\n<\/pre>\n

    \"9-07-06\"<\/p>\n

    \u5f53\u7136\uff0c\u53ef\u4ee5\u91cd\u5b9a\u5411\u5230\u67d0\u4e00\u4e2aURL<\/strong><\/p>\n

    [root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\nlocation ~* \\.(txt|doc)$ {\r\nif ( -f $request_filename) {\r\nroot \/usr\/local\/nginx\/html;\r\nrewrite ^\/(.*)$ http:\/\/gulass.cn last;\r\nbreak;\r\n}\r\n}<\/pre>\n

    \u5bf9\u76ee\u5f55\u8fdb\u884c\u9650\u5236\u7684\u65b9\u6cd5<\/strong><\/p>\n

    [root@linuxprobe ~]# mkdir -p \/usr\/local\/nginx\/html\/{linuxprobe,1mcloud}\r\n[root@linuxprobe ~]# echo linuxprobe > \/usr\/local\/nginx\/html\/linuxprobe\/index.html\r\n[root@linuxprobe ~]# echo 1mcloud > \/usr\/local\/nginx\/html\/1mcloud\/index.html\r\n[root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\nlocation \/linuxprobe\/ { return 404 ; }\r\nlocation \/1mcloud\/ { return 403 ; }\r\n\u6d4b\u8bd5\u8fd4\u56de\u7ed3\u679c\r\n<\/pre>\n

    \"9-07-08\"
    \n\"9-07-07\"<\/p>\n

    \u4e0a\u9762\u662f\u76f4\u63a5\u7ed9\u4e86\u53cd\u9988\u7684\u72b6\u6001\u5417\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5339\u914ddeny all\u65b9\u5f0f\u505a<\/p>\n

    [root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\nlocation ~ ^\/(linuxprobe)\/ {\r\ndeny all;\r\n}\r\n[root@linuxprobe ~]# \/usr\/local\/nginx\/sbin\/nginx -s reload\r\n<\/pre>\n

    \"9-07-09\"<\/p>\n

    \u6765\u6e90\u8bbf\u95ee\u63a7\u5236<\/strong><\/p>\n

    \u8fd9\u4e2a\u9700\u8981ngx_http_access_module\u6a21\u5757\u652f\u6301\uff0c\u4e0d\u8fc7\uff0c\u9ed8\u8ba4\u4f1a\u5b89\u88c5<\/p>\n

    [root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf \/\/\u5199\u6cd5\u7c7b\u4f3cApache\r\nlocation ~ ^\/(linuxprobe)\/ {\r\nallow 192.168.1.0\/24;\r\ndeny all;\r\n}\r\n<\/pre>\n

    \"9-07-11\"
    \n\u63a5\u7740\u4e0a\u9762\u7684\u5b9e\u9a8c\uff0c\u5c31\u53ef\u4ee5\u8bbf\u95ee\u4e86\uff0c\u4e0b\u9762\u662f\u9488\u5bf9\u6574\u4e2a\u7f51\u7ad9\u7684\u5199\u6cd5\uff0c\u5bf9\/\u9650\u5236\u5c31OK<\/p>\n

    location \/ {\r\nallow 192.168.1.0\/24;\r\ndeny all;\r\n}<\/pre>\n

    \u5f53\u7136\u53ef\u4ee5\u5199IP\uff0c\u53ef\u4ee5\u5199IP\u6bb5\uff0c\u4f46\u662f\u6ce8\u610f\u6b21\u5e8f\uff0c\u4e0a\u4e0b\u5339\u914d<\/p>\n

    \u540c\u65f6\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7if\u8bed\u53e5\u63a7\u5236\uff0c\u7ed9\u4ee5\u53cb\u597d\u7684\u9519\u8bef\u63d0\u793a<\/p>\n

    if ( $remote_addr = 10.1.1.55 ) {\r\nreturn 404;\r\n}<\/pre>\n

    #\u6b64\u5904remote_addr\u5730\u5740\u4e3a\u5f53\u524d\u7f16\u8f91\u6587\u6863\u7684\u7cfb\u7edfip\u5730\u5740
    \n\"9-07-12\"<\/p>\n

    IP\u548c301\u4f18\u5316<\/strong><\/span><\/div>\n

    \u6709\u65f6\u5019\uff0c\u6211\u4eec\u53d1\u73b0\u8bbf\u95ee\u7f51\u7ad9\u7684\u65f6\u5019\uff0c\u4f7f\u7528IP\u4e5f\u662f\u53ef\u4ee5\u5f97\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u8fd9\u4e00\u5c42\u7ed9\u5c4f\u853d\u6389\uff0c\u8ba9\u5176\u76f4\u63a5\u53cd\u9988\u7ed9403,\u4e5f\u53ef\u4ee5\u505a\u8df3\u8f6c<\/p>\n

    \u8df3\u8f6c\u7684\u505a\u6cd5\uff1a<\/strong><\/p>\n

    server {\r\nlisten 80 default_server;\r\nserver_name _;\r\nrewrite ^ http:\/\/gulass.cn$request_uri?;\r\n}<\/pre>\n

    403\u53cd\u9988\u7684\u505a\u6cd5<\/strong><\/p>\n

    server {\r\nlisten 80 default_server;\r\nserver_name _;\r\nreturn 403;\r\n}<\/pre>\n

    301\u8df3\u8f6c\u7684\u505a\u6cd5<\/strong><\/p>\n

    #\u5982\u6211\u4eec\u57df\u540d\u4e00\u822c\u5728\u89e3\u6790\u7684\u8fc7\u7a0b\u4e2d\uff0cgulass.cn\u4e00\u822c\u4f1a\u8df3\u8f6c\u5230gulass.cn,\u8bb0\u4f4f\u4fee\u6539\u672c\u5730hosts<\/p>\n

    server {\r\nlisten 80;\r\nroot \/usr\/share\/nginx\/html\/;\r\nserver_name gulass.cn gulass.cn;\r\nif ($host = 'a.com' ) {\r\nrewrite ^\/(.*)$ gulass.cn\/$1 permanent;\r\n}<\/pre>\n
    \u9632\u76d7\u94fe<\/strong><\/span><\/div>\n

    \u9632\u6b62\u522b\u4eba\u76f4\u63a5\u4ece\u4f60\u7f51\u7ad9\u5f15\u7528\u56fe\u7247\u7b49\u94fe\u63a5\uff0c\u6d88\u8017\u4e86\u4f60\u7684\u8d44\u6e90\u548c\u7f51\u7edc\u6d41\u91cf\uff0c\u90a3\u4e48\u6211\u4eec\u7684\u89e3\u51b3\u529e\u6cd5\u7531\u51e0\u79cd\uff1a<\/p>\n

    1\uff1a\u6c34\u5370\uff0c\u54c1\u724c\u5ba3\u4f20\uff0c\u4f60\u7684\u5e26\u5bbd\uff0c\u670d\u52a1\u5668\u8db3\u591f<\/p>\n

    2\uff1a\u9632\u706b\u5899\uff0c\u76f4\u63a5\u63a7\u5236\uff0c\u524d\u63d0\u662f\u4f60\u77e5\u9053IP\u6765\u6e90<\/p>\n

    3\uff1a\u9632\u76d7\u94fe\u7b56\u7565<\/p>\n

    \u4e0b\u9762\u7684\u65b9\u6cd5\u662f\u76f4\u63a5\u7ed9\u4e88404\u7684\u9519\u8bef\u63d0\u793a<\/p>\n

    location ~* \\.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar)$ {\r\nvalid_referers none blocked *.gulass.cn gulass.cn;\r\nif ($invalid_referer) {\r\nreturn 404;\r\n}<\/pre>\n

    \u540c\u65f6\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u72ec\u6709\u7684\uff0c\u56fe\u7247\u6bd4\u8f83\u5c0f\u7684\uff0c\u6765\u505arewrite\u8df3\u8f6c<\/p>\n

    location ~* \\.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar)$ {\r\nvalid_referers none blocked *.a.com a.com;\r\nif ($invalid_referer) {\r\nrewrite ^\/ http:\/\/gulass.cn\/img\/nolink.png;\r\n}<\/pre>\n

    \u9519\u8bef\u9875\u9762\u7684\u63d0\u793a<\/p>\n

    \u5bf9\u4e8e\u81ea\u5b9a\u4e49\u7684\u9519\u8bef\u9875\u9762\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5c06errorpage\u5199\u5165\u5230\u914d\u7f6e\u6587\u4ef6<\/p>\n

    error_page 404 \/404.html;<\/pre>\n

    \u5185\u90e8\u8eab\u4efd\u9a8c\u8bc1<\/strong><\/p>\n

    [root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\nlocation \/linuxprobe\/ {\r\nauth_basic \"haha\";\r\nauth_basic_user_file \/usr\/local\/nginx\/conf\/passwd;\r\n}<\/pre>\n

    \u7528\u6237\u521b\u5efa<\/p>\n

    [root@linuxprobe ~]# yum -y install httpd-tools\r\n[root@linuxprobe ~]# htpasswd -cb \/usr\/local\/nginx\/conf\/passwd linuxprobe 211212\r\n[root@linuxprobe ~]# chmod 400 \/usr\/local\/nginx\/conf\/passwd\r\n[root@linuxprobe ~]# chown nginx \/usr\/local\/nginx\/conf\/passwd\r\n[root@linuxprobe ~]# \/usr\/local\/nginx\/sbin\/nginx -s reload\r\n<\/pre>\n

    \"9-07-13\"<\/p>\n

    \u9632\u6b62DDOS\u653b\u51fb<\/strong><\/span><\/div>\n

    \u901a\u8fc7\u4f7f\u7528limit_conn_zone\u8fdb\u884c\u63a7\u5236\u5355\u4e2aIP\u6216\u8005\u57df\u540d\u7684\u8bbf\u95ee\u6b21\u6570<\/p>\n

    [root@linuxprobe ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf<\/pre>\n

    http\u5b57\u6bb5\u4e2d\u914d\u7f6e<\/p>\n

    limit_conn_zone $binary_remote_addr zone=addr:10m;<\/pre>\n

    server\u7684location\u5b57\u6bb5\u914d\u7f6e<\/p>\n

    location \/ {\r\nroot html;\r\nlimit_conn addr 1;<\/pre>\n

    #\u5728\u5176\u4ed6\u673a\u5668\u4e0a\u9762\u8fdb\u884c\u5e76\u53d1\u6d4b\u8bd5
    \n\"9-07-14\"<\/a><\/p>\n

    [root@linuxprobe ~]# webbench -c 5000 -t 120 http:\/\/10.1.1.83\/linuxprobe\/index.html<\/pre>\n

    #webbench\u5b89\u88c5\u8bf7\u53c2\u8003http:\/\/blog.sina.com.cn\/s\/blog_87113ac20102wag5.html<\/p>\n

    #nginx\u5339\u914d\u7b26\u4ecb\u7ecd<\/p>\n

    \r\n=    \u5f00\u5934\u8868\u793a\u7cbe\u786e\u5339\u914d\r\n^~   \u5f00\u5934\u8868\u793auri\u4ee5\u67d0\u4e2a\u5e38\u89c4\u5b57\u7b26\u4e32\u5f00\u5934\uff0c\u7406\u89e3\u4e3a\u5339\u914d url\u8def\u5f84\u5373\u53ef\u3002nginx\u4e0d\u5bf9url\u505a\u7f16\u7801\uff0c\u56e0\u6b64\u8bf7\u6c42\u4e3a\/static\/20%\/aa\uff0c\u53ef\u4ee5\u88ab\u89c4\u5219^~ \/static\/ \/aa\u5339\u914d\u5230\uff08\u6ce8\u610f\u662f\u7a7a\u683c\uff09\u3002\r\n~    \u5f00\u5934\u8868\u793a\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d\r\n~*   \u5f00\u5934\u8868\u793a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d\r\n!~\u548c!~*  \u5206\u522b\u4e3a\u533a\u5206\u5927\u5c0f\u5199\u4e0d\u5339\u914d\u53ca\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u4e0d\u5339\u914d\u7684\u6b63\u5219\r\n\/    \u901a\u7528\u5339\u914d\uff0c\u4efb\u4f55\u8bf7\u6c42\u90fd\u4f1a\u5339\u914d\u5230\u3002\r\n\u591a\u4e2alocation\u914d\u7f6e\u7684\u60c5\u51b5\u4e0b\u5339\u914d\u987a\u5e8f\u4e3a\uff08\u53c2\u8003\u8d44\u6599\u800c\u6765\uff0c\u8fd8\u672a\u5b9e\u9645\u9a8c\u8bc1\uff0c\u8bd5\u8bd5\u5c31\u77e5\u9053\u4e86\uff0c\u4e0d\u5fc5\u62d8\u6ce5\uff0c\u4ec5\u4f9b\u53c2\u8003\uff09:\r\n\u9996\u5148\u5339\u914d =\uff0c\u5176\u6b21\u5339\u914d^~, \u5176\u6b21\u662f\u6309\u6587\u4ef6\u4e2d\u987a\u5e8f\u7684\u6b63\u5219\u5339\u914d\uff0c\u6700\u540e\u662f\u4ea4\u7ed9 \/ \u901a\u7528\u5339\u914d\u3002\u5f53\u6709\u5339\u914d\u6210\u529f\u65f6\u5019\uff0c\u505c\u6b62\u5339\u914d\uff0c\u6309\u5f53\u524d\u5339\u914d\u89c4\u5219\u5904\u7406\u8bf7\u6c42\u3002<\/pre>\n

    \u672c\u6587\u539f\u521b\u5730\u5740\uff1a http:\/\/gulass.cn\/nginx-config-optimization.html<\/a>\u4f5c\u8005\uff1a\u738b\u8f89\uff0c\u5ba1\u6838\u5458\uff1a\u5cb3\u6c38<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

    \u5bfc\u8bfb \u7531\u4e8eNginx\u672c\u8eab\u7684\u4e00\u4e9b\u4f18\u70b9\uff0c\u8f7b\u91cf\uff0c\u5f00\u6e90\uff0c\u6613\u7528\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u516c\u53f8\u4f7f\u7528nginx\u4f5c\u4e3a\u81ea\u5df1\u516c\u53f8\u7684web\u5e94\u7528\u670d\u52a1 […]<\/p>\n","protected":false},"author":63,"featured_media":4896,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-29777","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/29777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=29777"}],"version-history":[{"count":15,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/29777\/revisions"}],"predecessor-version":[{"id":259101,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/29777\/revisions\/259101"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/4896"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=29777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=29777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=29777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}