{"id":693,"date":"2010-03-20T19:48:15","date_gmt":"2010-03-20T11:48:15","guid":{"rendered":"http:\/\/pony.xin\/?p=693"},"modified":"2021-03-12T20:56:05","modified_gmt":"2021-03-12T12:56:05","slug":"%e8%bd%ac%e5%b8%96%e4%bd%bf%e7%94%a8-nginx-%e6%8f%90%e5%8d%87%e7%bd%91%e7%ab%99%e8%ae%bf%e9%97%ae%e9%80%9f%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/lnmp.ivan.xin\/?p=693","title":{"rendered":"[\u8f6c\u5e16]\u4f7f\u7528 Nginx \u63d0\u5347\u7f51\u7ad9\u8bbf\u95ee\u901f\u5ea6"},"content":{"rendered":"<p><a name=\"N10053\"><span>Nginx \u7b80\u4ecb<\/span><\/a><\/p>\n<p>\n                <b>Nginx<\/b> (\"engine x\") \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684 HTTP \u548c \u53cd\u5411\u4ee3\u7406 \u670d\u52a1\u5668\uff0c\u4e5f\u662f\u4e00\u4e2a<br \/>\nIMAP\/POP3\/SMTP \u4ee3\u7406\u670d\u52a1\u5668\u3002 Nginx \u662f\u7531 Igor Sysoev \u4e3a\u4fc4\u7f57\u65af\u8bbf\u95ee\u91cf\u7b2c\u4e8c\u7684 Rambler.ru<br \/>\n\u7ad9\u70b9\u5f00\u53d1\u7684\uff0c\u5b83\u5df2\u7ecf\u5728\u8be5\u7ad9\u70b9\u8fd0\u884c\u8d85\u8fc7\u4e24\u5e74\u534a\u4e86\u3002 Igor \u5c06\u6e90\u4ee3\u7801\u4ee5\u7c7b BSD \u8bb8\u53ef\u8bc1\u7684\u5f62\u5f0f\u53d1\u5e03\u3002\u5c3d\u7ba1\u8fd8\u662f\u6d4b\u8bd5\u7248\uff0c\u4f46\u662f\uff0cNginx<br \/>\n\u5df2\u7ecf\u56e0\u4e3a\u5b83\u7684\u7a33\u5b9a\u6027\u3001\u4e30\u5bcc\u7684\u529f\u80fd\u96c6\u3001\u793a\u4f8b\u914d\u7f6e\u6587\u4ef6\u548c\u4f4e\u7cfb\u7edf\u8d44\u6e90\u7684\u6d88\u8017\u800c\u95fb\u540d\u4e86\u3002<\/p>\n<p>\u6839\u636e\u6700\u65b0\u4e00\u671f\uff0808 \u5e74 6 \u6708\u4efd\uff09\u7684 NetCraft \u8c03\u67e5\u62a5\u544a\u663e\u793a\uff0c\u5df2\u7ecf\u6709\u8d85\u8fc7\u4e24\u767e\u4e07\u7684\u4e3b\u673a\u4f7f\u7528\u4e86<br \/>\nNginx\uff0c\u8fd9\u4e2a\u6570\u5b57\u8d85\u8fc7\u4e86\u53e6\u5916\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684 HTTP \u670d\u52a1\u5668 lighttpd\uff0c \u6392\u540d\u7b2c\u56db\uff0c\u5e76\u4e14\u53d1\u5c55\u8fc5\u901f\u3002\u4e0b\u9762\u662f\u8fd9\u4efd\u62a5\u544a\u7684\u524d\u51e0\u540d\u7684\u62a5\u8868\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td>\n                        <b>\u4ea7\u54c1<\/b>\n                    <\/td>\n<td>\n                        <b>\u7f51\u7ad9\u6570<\/b>\n                    <\/td>\n<\/tr>\n<tr>\n<td>Apache\n<\/td>\n<td>84,309,103\n<\/td>\n<\/tr>\n<tr>\n<td>IIS\n<\/td>\n<td>60,987,087\n<\/td>\n<\/tr>\n<tr>\n<td>Google GFE\n<\/td>\n<td>10,465,178\n<\/td>\n<\/tr>\n<tr>\n<td>Unknown\n<\/td>\n<td>4,903,174\n<\/td>\n<\/tr>\n<tr>\n<td>nginx\n<\/td>\n<td>2,125,160\n<\/td>\n<\/tr>\n<tr>\n<td>Oversee\n<\/td>\n<td>1,953,848\n<\/td>\n<\/tr>\n<tr>\n<td>lighttpd\n<\/td>\n<td>1,532,952\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>\u5173\u4e8e\u8fd9\u671f\u8c03\u67e5\u62a5\u544a\u7684\u66f4\u8be6\u7ec6\u4fe1\u606f\u8bf7\u770b\u4e0b\u9762\u94fe\u63a5\uff1a<\/p>\n<p>\n                <a href=\"http:\/\/survey.netcraft.com\/Reports\/200806\/\" target=\"_blank\" rel=\"noopener\">http:\/\/survey.netcraft.com\/Reports\/200806\/<\/a>\n            <\/p>\n<p>\u4e0b\u56fe\u662f\u6700\u8fd1\u51e0\u4e2a\u6708\u4f7f\u7528 Nginx \u548c lighttpd \u7684\u7f51\u7ad9\u6570\u6bd4\u8f83<\/p>\n<p><a name=\"N100C8\"><b>\u56fe 1. \u6700\u8fd1\u51e0\u4e2a\u6708\u4f7f\u7528 Nginx \u548c lighttpd<br \/>\n\u7684\u7f51\u7ad9\u6570\u6bd4\u8f83<\/b><\/a><br \/>\n                <img loading=\"lazy\" decoding=\"async\" alt=\"\u56fe 1. \u6700\u8fd1\u51e0\u4e2a\u6708\u4f7f\u7528 Nginx \u548c lighttpd \u7684\u7f51\u7ad9\u6570\u6bd4\u8f83\" src=\"http:\/\/www.ibm.com\/developerworks\/cn\/web\/wa-lo-nginx\/image001.png\" height=\"171\" width=\"257\" \/><br \/>\n            <\/p>\n<p><a name=\"N100D5\"><span>\u4f7f\u7528 Nginx \u524d\u5fc5\u987b\u4e86\u89e3\u7684\u4e8b\u9879<\/span><\/a><\/p>\n<ol type=\"1\">\n<li>\u76ee\u524d\u5b98\u65b9 Nginx \u5e76\u4e0d\u652f\u6301 Windows\uff0c\u60a8\u53ea\u80fd\u5728\u5305\u62ec Linux\u3001UNIX\u3001BSD<br \/>\n\u7cfb\u7edf\u4e0b\u5b89\u88c5\u548c\u4f7f\u7528\uff1b<\/li>\n<li>Nginx \u672c\u8eab\u53ea\u662f\u4e00\u4e2a HTTP \u548c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5b83\u65e0\u6cd5\u50cf Apache<br \/>\n\u4e00\u6837\u901a\u8fc7\u5b89\u88c5\u5404\u79cd\u6a21\u5757\u6765\u652f\u6301\u4e0d\u540c\u7684\u9875\u9762\u811a\u672c\uff0c\u4f8b\u5982 PHP\u3001CGI \u7b49\uff1b<\/li>\n<li>Nginx \u652f\u6301\u7b80\u5355\u7684\u8d1f\u8f7d\u5747\u8861\u548c\u5bb9\u9519\uff1b<\/li>\n<li>\u652f\u6301\u4f5c\u4e3a\u57fa\u672c HTTP \u670d\u52a1\u5668\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u65e5\u5fd7\u3001\u538b\u7f29\u3001Byte ranges\u3001Chunked<br \/>\nresponses\u3001SSL\u3001\u865a\u62df\u4e3b\u673a\u7b49\u7b49\uff0c\u5e94\u6709\u5c3d\u6709\u3002<\/li>\n<\/ol>\n<p><a name=\"N100EC\"><span>\u5728 Linux \u4e0b\u5b89\u88c5 Nginx<\/span><\/a><\/p>\n<p>\u4e3a\u4e86\u786e\u4fdd\u80fd\u5728 Nginx \u4e2d\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u66f4\u7075\u6d3b\u7684\u914d\u7f6e\uff0c\u5b89\u88c5\u4e4b\u524d\u9700\u8981\u786e\u5b9a\u7cfb\u7edf\u662f\u5426\u5b89\u88c5\u6709 PCRE\uff08Perl<br \/>\nCompatible Regular Expressions\uff09\u5305\u3002\u60a8\u53ef\u4ee5\u5230 <a href=\"ftp:\/\/ftp.csx.cam.ac.uk\/pub\/software\/programming\/pcre\/\" target=\"_blank\" rel=\"noopener\">ftp:\/\/ftp.csx.cam.ac.uk\/pub\/software\/programming\/pcre\/<\/a><br \/>\n \u4e0b\u8f7d\u6700\u65b0\u7684 PCRE \u6e90\u7801\u5305\uff0c\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u4e0b\u8f7d\u7f16\u8bd1\u548c\u5b89\u88c5 PCRE \u5305\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre># wget ftp:\/\/ftp.csx.cam.ac.uk\/pub\/software\/programming\/pcre\/pcre-7.7.tar.gz<br># tar zxvf pcre-7.7.tar.gz<br># cd pcre-7.7<br># .\/configure<br># make<br># make install<br>\t\t\t<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>\u63a5\u4e0b\u6765\u5b89\u88c5 Nginx\uff0cNginx<br \/>\n\u4e00\u822c\u6709\u4e24\u4e2a\u7248\u672c\uff0c\u5206\u522b\u662f\u7a33\u5b9a\u7248\u548c\u5f00\u53d1\u7248\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u60a8\u7684\u76ee\u7684\u6765\u9009\u62e9\u8fd9\u4e24\u4e2a\u7248\u672c\u7684\u5176\u4e2d\u4e00\u4e2a\uff0c\u4e0b\u9762\u662f\u628a Nginx \u5b89\u88c5\u5230 \/opt\/nginx<br \/>\n\u76ee\u5f55\u4e0b\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre># wget http:\/\/sysoev.ru\/nginx\/nginx-0.6.31.tar.gz<br># tar zxvf nginx-0.6.31.tar.gz<br># cd nginx-0.6.31<br># .\/configure --with-http_stub_status_module \u2013prefix=\/opt\/nginx<br># make<br># make install<br>\t\t\t<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>\u5176\u4e2d\u53c2\u6570 <code>--with-http_stub_status_module<\/code> \u662f\u4e3a\u4e86\u542f\u7528<br \/>\nnginx \u7684 NginxStatus \u529f\u80fd\uff0c\u7528\u6765\u76d1\u63a7 Nginx \u7684\u5f53\u524d\u72b6\u6001\u3002<\/p>\n<p>\u5b89\u88c5\u6210\u529f\u540e \/opt\/nginx \u76ee\u5f55\u4e0b\u6709\u56db\u4e2a\u5b50\u76ee\u5f55\u5206\u522b\u662f\uff1aconf\u3001html\u3001logs\u3001sbin \u3002\u5176\u4e2d<br \/>\nNginx \u7684\u914d\u7f6e\u6587\u4ef6\u5b58\u653e\u4e8e conf\/nginx.conf\uff0cNginx \u53ea\u6709\u4e00\u4e2a\u7a0b\u5e8f\u6587\u4ef6\u4f4d\u4e8e sbin \u76ee\u5f55\u4e0b\u7684 nginx \u6587\u4ef6\u3002\u786e\u4fdd\u7cfb\u7edf\u7684<br \/>\n 80 \u7aef\u53e3\u6ca1\u88ab\u5176\u4ed6\u7a0b\u5e8f\u5360\u7528\uff0c\u8fd0\u884c sbin\/nginx \u547d\u4ee4\u6765\u542f\u52a8 Nginx\uff0c\u6253\u5f00\u6d4f\u89c8\u5668\u8bbf\u95ee\u6b64\u673a\u5668\u7684 IP\uff0c\u5982\u679c\u6d4f\u89c8\u5668\u51fa\u73b0 Welcome<br \/>\nto nginx! \u5219\u8868\u793a Nginx \u5df2\u7ecf\u5b89\u88c5\u5e76\u8fd0\u884c\u6210\u529f\u3002<\/p>\n<p><a name=\"N1010F\"><span>\u5e38\u7528\u7684 Nginx \u53c2\u6570\u548c\u63a7\u5236<\/span><\/a><\/p>\n<p><a name=\"N10116\"><span>\u7a0b\u5e8f\u8fd0\u884c\u53c2\u6570<\/span><\/a><\/p>\n<p>Nginx \u5b89\u88c5\u540e\u53ea\u6709\u4e00\u4e2a\u7a0b\u5e8f\u6587\u4ef6\uff0c\u672c\u8eab\u5e76\u4e0d\u63d0\u4f9b\u5404\u79cd\u7ba1\u7406\u7a0b\u5e8f\uff0c\u5b83\u662f\u4f7f\u7528\u53c2\u6570\u548c\u7cfb\u7edf\u4fe1\u53f7\u673a\u5236\u5bf9 Nginx<br \/>\n\u8fdb\u7a0b\u672c\u8eab\u8fdb\u884c\u63a7\u5236\u7684\u3002 Nginx \u7684\u53c2\u6570\u5305\u62ec\u6709\u5982\u4e0b\u51e0\u4e2a\uff1a<\/p>\n<p>\n                <b>-c<\/b> &lt;path_to_config&gt;\uff1a\u4f7f\u7528\u6307\u5b9a\u7684\u914d\u7f6e\u6587\u4ef6\u800c\u4e0d\u662f conf \u76ee\u5f55\u4e0b\u7684<br \/>\nnginx.conf \u3002<\/p>\n<p>\n                <b>-t<\/b>\uff1a\u6d4b\u8bd5\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u6b63\u786e\uff0c\u5728\u8fd0\u884c\u65f6\u9700\u8981\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u7684\u65f6\u5019\uff0c\u6b64\u547d\u4ee4\u975e\u5e38\u91cd\u8981\uff0c\u7528\u6765\u68c0\u6d4b\u6240\u4fee\u6539\u7684\u914d\u7f6e\u6587<br \/>\n\u4ef6\u662f\u5426\u6709\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p>\n                <b>-v<\/b>\uff1a\u663e\u793a nginx \u7248\u672c\u53f7\u3002<\/p>\n<p>\n                <b>-V<\/b>\uff1a\u663e\u793a nginx \u7684\u7248\u672c\u53f7\u4ee5\u53ca\u7f16\u8bd1\u73af\u5883\u4fe1\u606f\u4ee5\u53ca\u7f16\u8bd1\u65f6\u7684\u53c2\u6570\u3002<\/p>\n<p>\u4f8b\u5982\u6211\u4eec\u8981\u6d4b\u8bd5\u67d0\u4e2a\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u4e66\u5199\u6b63\u786e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre>sbin\/nginx \u2013 t \u2013 c conf\/nginx2.conf<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p><a name=\"N1013E\"><span>\u901a\u8fc7\u4fe1\u53f7\u5bf9 Nginx<br \/>\n\u8fdb\u884c\u63a7\u5236<\/span><\/a><\/p>\n<p>Nginx \u652f\u6301\u4e0b\u8868\u4e2d\u7684\u4fe1\u53f7\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td>\n                        <b>\u4fe1\u53f7\u540d<\/b>\n                    <\/td>\n<td>\n                        <b>\u4f5c\u7528\u63cf\u8ff0<\/b>\n                    <\/td>\n<\/tr>\n<tr>\n<td>\n TERM, INT\n<\/td>\n<td>\n\u5feb\u901f\u5173\u95ed\u7a0b\u5e8f\uff0c\u4e2d\u6b62\u5f53\u524d\u6b63\u5728\u5904\u7406\u7684\u8bf7\u6c42\n<\/td>\n<\/tr>\n<tr>\n<td>\n QUIT\n<\/td>\n<td>\n\u5904\u7406\u5b8c\u5f53\u524d\u8bf7\u6c42\u540e\uff0c\u5173\u95ed\u7a0b\u5e8f\n<\/td>\n<\/tr>\n<tr>\n<td>\n HUP\n<\/td>\n<td>\n\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\uff0c\u5e76\u5f00\u542f\u65b0\u7684\u5de5\u4f5c\u8fdb\u7a0b\uff0c\u5173\u95ed\u5c31\u7684\u8fdb\u7a0b\uff0c\u6b64\u64cd\u4f5c\u4e0d\u4f1a\u4e2d\u65ad\u8bf7\u6c42\n<\/td>\n<\/tr>\n<tr>\n<td>\n USR1\n<\/td>\n<td>\n\u91cd\u65b0\u6253\u5f00\u65e5\u5fd7\u6587\u4ef6\uff0c\u7528\u4e8e\u5207\u6362\u65e5\u5fd7\uff0c\u4f8b\u5982\u6bcf\u5929\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u65e5\u5fd7\u6587\u4ef6\n<\/td>\n<\/tr>\n<tr>\n<td>\n USR2\n<\/td>\n<td>\n\u5e73\u6ed1\u5347\u7ea7\u53ef\u6267\u884c\u7a0b\u5e8f\n<\/td>\n<\/tr>\n<tr>\n<td>\n WINCH\n<\/td>\n<td>\n\u4ece\u5bb9\u5173\u95ed\u5de5\u4f5c\u8fdb\u7a0b\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>\u6709\u4e24\u79cd\u65b9\u5f0f\u6765\u901a\u8fc7\u8fd9\u4e9b\u4fe1\u53f7\u53bb\u63a7\u5236 Nginx\uff0c\u7b2c\u4e00\u662f\u901a\u8fc7 logs \u76ee\u5f55\u4e0b\u7684 nginx.pid \u67e5\u770b\u5f53\u524d\u8fd0\u884c\u7684<br \/>\nNginx \u7684\u8fdb\u7a0b ID\uff0c\u901a\u8fc7 <code>kill \u2013 XXX &lt;pid&gt;<\/code> \u6765\u63a7\u5236 Nginx\uff0c\u5176\u4e2d XXX<br \/>\n\u5c31\u662f\u4e0a\u8868\u4e2d\u5217\u51fa\u7684\u4fe1\u53f7\u540d\u3002\u5982\u679c\u60a8\u7684\u7cfb\u7edf\u4e2d\u53ea\u6709\u4e00\u4e2a Nginx \u8fdb\u7a0b\uff0c\u90a3\u60a8\u4e5f\u53ef\u4ee5\u901a\u8fc7 <code>killall<\/code> \u547d\u4ee4\u6765\u5b8c\u6210\uff0c\u4f8b\u5982\u8fd0\u884c<br \/>\n <code>killall \u2013 s HUP nginx<\/code> \u6765\u8ba9 Nginx \u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u3002<\/p>\n<p><a name=\"N101A4\"><span>\u914d\u7f6e Nginx<\/span><\/a><\/p>\n<p>\u5148\u6765\u770b\u4e00\u4e2a\u5b9e\u9645\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre> user  nobody;# \u5de5\u4f5c\u8fdb\u7a0b\u7684\u5c5e\u4e3b<br> worker_processes  4;# \u5de5\u4f5c\u8fdb\u7a0b\u6570\uff0c\u4e00\u822c\u4e0e CPU \u6838\u6570\u7b49\u540c<br><br> #error_log  logs\/error.log; <br> #error_log  logs\/error.log  notice; <br> #error_log  logs\/error.log  info; <br><br> #pid        logs\/nginx.pid; <br><br> events { <br>    use epoll;#Linux \u4e0b\u6027\u80fd\u6700\u597d\u7684 event \u6a21\u5f0f<br>    worker_connections  2048;# \u6bcf\u4e2a\u5de5\u4f5c\u8fdb\u7a0b\u5141\u8bb8\u6700\u5927\u7684\u540c\u65f6\u8fde\u63a5\u6570<br> } <br><br> http { <br>    include       mime.types; <br>    default_type  application\/octet-stream; <br><br>    #log_format  main  '$remote_addr - $remote_user [$time_local] $request ' <br>    #                  '\"$status\" $body_bytes_sent \"$http_referer\" ' <br>    #                  '\"$http_user_agent\" \"$http_x_forwarded_for\"'; <br><br>    #access_log  off; <br>    access_log  logs\/access.log;# \u65e5\u5fd7\u6587\u4ef6\u540d<br><br>    sendfile        on; <br>    #tcp_nopush     on; <br>    tcp_nodelay     on; <br><br>    keepalive_timeout  65; <br><br>    include \t gzip.conf; <br>    <br>    # \u96c6\u7fa4\u4e2d\u7684\u6240\u6709\u540e\u53f0\u670d\u52a1\u5668\u7684\u914d\u7f6e\u4fe1\u606f<br>    upstream tomcats { <br>\t server 192.168.0.11:8080 weight=10; <br>\t server 192.168.0.11:8081 weight=10; <br>\t server 192.168.0.12:8080 weight=10; <br>\t server 192.168.0.12:8081 weight=10; <br>\t server 192.168.0.13:8080 weight=10; <br>\t server 192.168.0.13:8081 weight=10; <br>    } <br><br>    server { <br>        listen       80;#HTTP \u7684\u7aef\u53e3<br>        server_name  localhost; <br><br>        charset utf-8; <br><br>        #access_log  logs\/host.access.log  main; <br><br>\t location ~ ^\/NginxStatus\/ { <br>\t    stub_status on; #Nginx \u72b6\u6001\u76d1\u63a7\u914d\u7f6e<br>\t    access_log off; <br>\t } <br><br>\t location ~ ^\/(WEB-INF)\/ { <br>\t    deny all; <br>\t } <br>\t<br><br>\t location ~ \\.(htm|html|asp|php|gif|jpg|jpeg|png|bmp|ico|rar|css|js|<br>\t zip|java|jar|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma)$ { <br>             root \/opt\/webapp; <br>\t    expires 24h; <br>        } <br><br>        location \/ { <br>\t    proxy_pass http:\/\/tomcats;# \u53cd\u5411\u4ee3\u7406<br>\t    include proxy.conf; <br>        } <br><br>        error_page 404 \/html\/404.html; <br><br>        # redirect server error pages to the static page \/50x.html <br>        # <br>\t error_page 502 503 \/html\/502.html; <br>        error_page 500 504 \/50x.html; <br>        location = \/50x.html { <br>            root   html; <br>        } <br>    } <br> } <br><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p><a name=\"N101B2\"><span>Nginx \u76d1\u63a7<\/span><\/a><\/p>\n<p>\u4e0a\u9762\u662f\u4e00\u4e2a\u5b9e\u9645\u7f51\u7ad9\u7684\u914d\u7f6e\u5b9e\u4f8b\uff0c\u5176\u4e2d\u7070\u8272\u6587\u5b57\u4e3a\u914d\u7f6e\u8bf4\u660e\u3002\u4e0a\u8ff0\u914d\u7f6e\u4e2d\uff0c\u9996\u5148\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a location ~<br \/>\n^\/NginxStatus\/\uff0c\u8fd9\u6837\u901a\u8fc7 http:\/\/localhost\/NginxStatus\/ \u5c31\u53ef\u4ee5\u76d1\u63a7\u5230 Nginx<br \/>\n\u7684\u8fd0\u884c\u4fe1\u606f\uff0c\u663e\u793a\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre>Active connections: 70 <br>server accepts handled requests<br> 14553819 14553819 19239266 <br>Reading: 0 Writing: 3 Waiting: 67 <br>\t\t\t<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>NginxStatus \u663e\u793a\u7684\u5185\u5bb9\u610f\u601d\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>active connections \u2013 \u5f53\u524d Nginx \u6b63\u5904\u7406\u7684\u6d3b\u52a8\u8fde\u63a5\u6570\u3002<\/li>\n<li>server accepts handled requests -- \u603b\u5171\u5904\u7406\u4e86 14553819<br \/>\n\u4e2a\u8fde\u63a5 , \u6210\u529f\u521b\u5efa 14553819 \u6b21\u63e1\u624b ( \u8bc1\u660e\u4e2d\u95f4\u6ca1\u6709\u5931\u8d25\u7684 ), \u603b\u5171\u5904\u7406\u4e86 19239266 \u4e2a\u8bf7\u6c42 ( \u5e73\u5747\u6bcf\u6b21\u63e1\u624b\u5904\u7406\u4e86<br \/>\n1.3 \u4e2a\u6570\u636e\u8bf7\u6c42 )\u3002<\/li>\n<li>reading -- nginx \u8bfb\u53d6\u5230\u5ba2\u6237\u7aef\u7684 Header \u4fe1\u606f\u6570\u3002<\/li>\n<li>writing -- nginx \u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u7684 Header \u4fe1\u606f\u6570\u3002<\/li>\n<li>waiting -- \u5f00\u542f keep-alive \u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e2a\u503c\u7b49\u4e8e active -<br \/>\n(reading + writing)\uff0c\u610f\u601d\u5c31\u662f Nginx \u5df2\u7ecf\u5904\u7406\u5b8c\u6b63\u5728\u7b49\u5019\u4e0b\u4e00\u6b21\u8bf7\u6c42\u6307\u4ee4\u7684\u9a7b\u7559\u8fde\u63a5\u3002<\/li>\n<\/ul>\n<p><a name=\"N101D4\"><span>\u9759\u6001\u6587\u4ef6\u5904\u7406<\/span><\/a><\/p>\n<p>\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u6211\u4eec\u53ef\u8ba9 Nginx \u8bc6\u522b\u51fa\u5404\u79cd\u9759\u6001\u6587\u4ef6\uff0c\u4f8b\u5982 images \u8def\u5f84\u4e0b\u7684\u6240\u6709\u8bf7\u6c42\u53ef\u4ee5\u5199\u4e3a\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre>location ~ ^\/images\/ {<br>    root \/opt\/webapp\/images;<br>}<br>\t\t\t<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>\u800c\u4e0b\u9762\u7684\u914d\u7f6e\u5219\u5b9a\u4e49\u4e86\u51e0\u79cd\u6587\u4ef6\u7c7b\u578b\u7684\u8bf7\u6c42\u5904\u7406\u65b9\u5f0f\u3002<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre>location ~ \\.(htm|html|gif|jpg|jpeg|png|bmp|ico|css|js|txt)$ {<br>    root \/opt\/webapp;<br>    expires 24h;<br>}<br>\t\t\t<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>\u5bf9\u4e8e\u4f8b\u5982\u56fe\u7247\u3001\u9759\u6001 HTML \u6587\u4ef6\u3001js \u811a\u672c\u6587\u4ef6\u548c css \u6837\u5f0f\u6587\u4ef6\u7b49\uff0c\u6211\u4eec\u5e0c\u671b Nginx<br \/>\n\u76f4\u63a5\u5904\u7406\u5e76\u8fd4\u56de\u7ed9\u6d4f\u89c8\u5668\uff0c\u8fd9\u6837\u53ef\u4ee5\u5927\u5927\u7684\u52a0\u5feb\u7f51\u9875\u6d4f\u89c8\u65f6\u7684\u901f\u5ea6\u3002\u56e0\u6b64\u5bf9\u4e8e\u8fd9\u7c7b\u6587\u4ef6\u6211\u4eec\u9700\u8981\u901a\u8fc7 root<br \/>\n\u6307\u4ee4\u6765\u6307\u5b9a\u6587\u4ef6\u7684\u5b58\u653e\u8def\u5f84\uff0c\u540c\u65f6\u56e0\u4e3a\u8fd9\u7c7b\u6587\u4ef6\u5e76\u4e0d\u5e38\u4fee\u6539\uff0c\u901a\u8fc7 <code>expires<\/code><br \/>\n\u6307\u4ee4\u6765\u63a7\u5236\u5176\u5728\u6d4f\u89c8\u5668\u7684\u7f13\u5b58\uff0c\u4ee5\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8bf7\u6c42\u3002 <code>expires<\/code> \u6307\u4ee4\u53ef\u4ee5\u63a7\u5236 HTTP \u5e94\u7b54\u4e2d\u7684\u201c Expires<br \/>\n\u201d\u548c\u201c Cache-Control \u201d\u7684\u5934\u6807\uff08\u8d77\u5230\u63a7\u5236\u9875\u9762\u7f13\u5b58\u7684\u4f5c\u7528\uff09\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4f8b\u5982\u4ee5\u4e0b\u7684\u683c\u5f0f\u6765\u4e66\u5199 Expires\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre>expires 1 January, 1970, 00:00:01 GMT;<br>expires 60s;<br>expires 30m;<br>expires 24h;<br>expires 1d;<br>expires max;<br>expires off;<br>\t\t\t<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p><a name=\"N101F7\"><span>\u52a8\u6001\u9875\u9762\u8bf7\u6c42\u5904\u7406<\/span><\/a><\/p>\n<p>Nginx \u672c\u8eab\u5e76\u4e0d\u652f\u6301\u73b0\u5728\u6d41\u884c\u7684 JSP\u3001ASP\u3001PHP\u3001PERL<br \/>\n\u7b49\u52a8\u6001\u9875\u9762\uff0c\u4f46\u662f\u5b83\u53ef\u4ee5\u901a\u8fc7\u53cd\u5411\u4ee3\u7406\u5c06\u8bf7\u6c42\u53d1\u9001\u5230\u540e\u7aef\u7684\u670d\u52a1\u5668\uff0c\u4f8b\u5982 Tomcat\u3001Apache\u3001IIS<br \/>\n\u7b49\u6765\u5b8c\u6210\u52a8\u6001\u9875\u9762\u7684\u8bf7\u6c42\u5904\u7406\u3002\u524d\u9762\u7684\u914d\u7f6e\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5b9a\u4e49\u4e86\u7531 Nginx \u76f4\u63a5\u5904\u7406\u7684\u4e00\u4e9b\u9759\u6001\u6587\u4ef6\u8bf7\u6c42\u540e\uff0c\u5176\u4ed6\u6240\u6709\u7684\u8bf7\u6c42\u901a\u8fc7<br \/>\nproxy_pass \u6307\u4ee4\u4f20\u9001\u7ed9\u540e\u7aef\u7684\u670d\u52a1\u5668\uff08\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\u662f Tomcat\uff09\u3002\u6700\u7b80\u5355\u7684 <code>proxy_pass<\/code><br \/>\n\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre>location \/ {<br>    proxy_pass        http:\/\/localhost:8080;<br>    proxy_set_header  X-Real-IP  $remote_addr;<br>}<br>\t\t\t<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u6ca1\u6709\u4f7f\u7528\u5230\u96c6\u7fa4\uff0c\u800c\u662f\u5c06\u8bf7\u6c42\u76f4\u63a5\u9001\u5230\u8fd0\u884c\u5728 8080 \u7aef\u53e3\u7684 Tomcat \u670d\u52a1\u4e0a\u6765\u5b8c\u6210\u7c7b\u4f3c JSP \u548c<br \/>\nServlet \u7684\u8bf7\u6c42\u5904\u7406\u3002<\/p>\n<p>\u5f53\u9875\u9762\u7684\u8bbf\u95ee\u91cf\u975e\u5e38\u5927\u7684\u65f6\u5019\uff0c\u5f80\u5f80\u9700\u8981\u591a\u4e2a\u5e94\u7528\u670d\u52a1\u5668\u6765\u5171\u540c\u627f\u62c5\u52a8\u6001\u9875\u9762\u7684\u6267\u884c\u64cd\u4f5c\uff0c\u8fd9\u65f6\u6211\u4eec\u5c31\u9700\u8981\u4f7f\u7528\u96c6\u7fa4\u7684\u67b6\u6784\u3002<br \/>\nNginx \u901a\u8fc7 <code>upstream<\/code> \u6307\u4ee4\u6765\u5b9a\u4e49\u4e00\u4e2a\u670d\u52a1\u5668\u7684\u96c6\u7fa4\uff0c\u6700\u524d\u9762\u90a3\u4e2a\u5b8c\u6574\u7684\u4f8b\u5b50\u4e2d\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<br \/>\ntomcats \u7684\u96c6\u7fa4\uff0c\u8fd9\u4e2a\u96c6\u7fa4\u4e2d\u5305\u62ec\u4e86\u4e09\u53f0\u670d\u52a1\u5668\u5171 6 \u4e2a Tomcat \u670d\u52a1\u3002\u800c proxy_pass \u6307\u4ee4\u7684\u5199\u6cd5\u53d8\u6210\u4e86\uff1a<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td>\n<pre>location \/ {<br>    proxy_pass        http:\/\/tomcats;<br>    proxy_set_header  X-Real-IP  $remote_addr;<br>}<br>\t\t\t<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>\u5728 Nginx \u7684\u96c6\u7fa4\u914d\u7f6e\u4e2d\uff0cNginx<br \/>\n\u4f7f\u7528\u6700\u7b80\u5355\u7684\u5e73\u5747\u5206\u914d\u89c4\u5219\u7ed9\u96c6\u7fa4\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u5206\u914d\u8bf7\u6c42\u3002\u4e00\u65e6\u67d0\u4e2a\u8282\u70b9\u5931\u6548\u65f6\uff0c\u6216\u8005\u91cd\u65b0\u8d77\u6548\u65f6\uff0cNginx<br \/>\n\u90fd\u4f1a\u975e\u5e38\u53ca\u65f6\u7684\u5904\u7406\u72b6\u6001\u7684\u53d8\u5316\uff0c\u4ee5\u4fdd\u8bc1\u4e0d\u4f1a\u5f71\u54cd\u5230\u7528\u6237\u7684\u8bbf\u95ee\u3002<\/p>\n<p><a name=\"5.\u603b\u7ed3|outline\"><span>\u603b\u7ed3<\/span><\/a><\/p>\n<p>\u5c3d\u7ba1\u6574\u4e2a\u7a0b\u5e8f\u5305\u53ea\u6709\u4e94\u767e\u591a K\uff0c\u4f46\u9ebb\u96c0\u867d\u5c0f\u3001\u4e94\u810f\u4ff1\u5168\u3002 Nginx<br \/>\n\u5b98\u65b9\u63d0\u4f9b\u7684\u5404\u79cd\u529f\u80fd\u6a21\u5757\u5e94\u6709\u5c3d\u6709\uff0c\u7ed3\u5408\u8fd9\u4e9b\u6a21\u5757\u53ef\u4ee5\u5b8c\u6574\u5404\u79cd\u5404\u6837\u7684\u914d\u7f6e\u8981\u6c42\uff0c\u4f8b\u5982\uff1a\u538b\u7f29\u3001\u9632\u76d7\u94fe\u3001\u96c6\u7fa4\u3001FastCGI\u3001\u6d41\u5a92\u4f53\u670d\u52a1\u5668\u3001<br \/>\nMemcached \u652f\u6301\u3001URL \u91cd\u5199\u7b49\u7b49\uff0c\u66f4\u5173\u952e\u7684\u662f Nginx \u62e5\u6709 Apache \u548c\u5176\u4ed6 HTTP<br \/>\n\u670d\u52a1\u5668\u65e0\u6cd5\u6bd4\u62df\u7684\u9ad8\u6027\u80fd\u3002\u60a8\u751a\u81f3\u53ef\u4ee5\u5728\u4e0d\u6539\u53d8\u539f\u6709\u7f51\u7ad9\u7684\u67b6\u6784\u4e0a\uff0c\u901a\u8fc7\u5728\u524d\u7aef\u5f15\u5165 Nginx \u6765\u63d0\u5347\u7f51\u7ad9\u7684\u8bbf\u95ee\u901f\u5ea6\u3002<\/p>\n<p>\u672c\u6587\u53ea\u662f\u7b80\u5355\u4ecb\u7ecd\u4e86 Nginx \u7684\u5b89\u88c5\u4ee5\u53ca\u5e38\u89c1\u7684\u57fa\u672c\u7684\u914d\u7f6e\u548c\u4f7f\u7528\uff0c\u66f4\u591a\u5173\u4e8e Nginx<br \/>\n\u7684\u4fe1\u606f\u8bf7\u9605\u8bfb\u6587\u7ae0\u540e\u9762\u7684\u53c2\u8003\u8d44\u6e90\u3002\u5728\u8fd9\u91cc\u8981\u975e\u5e38\u611f\u8c22\u6211\u7684\u670b\u53cb\u2014\u2014\u9648\u78ca\uff08chanix@msn.com\uff09\uff0c\u4ed6\u4e00\u76f4\u5728\u505a Nginx \u7684\u4e2d\u6587 WIKI\uff08<a href=\"http:\/\/wiki.codemongers.com\/NginxChs\" target=\"_blank\" rel=\"noopener\">http:\/\/wiki.codemongers.com\/NginxChs<\/a>\uff09\uff0c<br \/>\n\u540c\u65f6\u4e5f\u662f\u4ed6\u4ecb\u7ecd\u7ed9\u6211\u8fd9\u4e48\u597d\u7684\u4e00\u6b3e\u8f6f\u4ef6\u3002<\/p>\n<p>\u5982\u679c\u60a8\u7684\u7f51\u7ad9\u662f\u8fd0\u884c\u5728 Linux \u4e0b\uff0c\u5982\u679c\u60a8\u5e76\u6ca1\u6709\u4f7f\u7528\u4e00\u4e9b\u975e\u5e38\u590d\u6742\u7684\u800c\u4e14\u786e\u5b9a Nginx<br \/>\n\u65e0\u6cd5\u5b8c\u6210\u7684\u529f\u80fd\uff0c\u90a3\u60a8\u5e94\u8be5\u8bd5\u8bd5 Nginx \u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.ibm.com\/developerworks\/cn\/web\/wa-lo-nginx\/image001.png\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx \u7b80\u4ecb Nginx (\"engine x\") \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684 HTTP \u548c \u53cd\u5411\u4ee3\u7406 \u670d\u52a1\u5668\uff0c\u4e5f\u662f\u4e00...<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15329],"tags":[],"class_list":["post-693","post","type-post","status-publish","format-standard","hentry","category-nginx"],"_links":{"self":[{"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/posts\/693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=693"}],"version-history":[{"count":1,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/posts\/693\/revisions"}],"predecessor-version":[{"id":694,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=\/wp\/v2\/posts\/693\/revisions\/694"}],"wp:attachment":[{"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lnmp.ivan.xin\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}