{"id":170426,"date":"2020-02-03T10:44:20","date_gmt":"2020-02-03T02:44:20","guid":{"rendered":"https:\/\/gulass.cn\/?p=170426"},"modified":"2020-01-23T09:45:39","modified_gmt":"2020-01-23T01:45:39","slug":"nginx","status":"publish","type":"post","link":"https:\/\/gulass.cn\/nginx.html","title":{"rendered":"Nginx\u5982\u6b64\u4e4b\u5feb"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | nignx\u7684\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u4e00\u822c\u4f18\u5316\u540e\uff0c\u5cf0\u503c\u80fd\u4fdd\u6301\u5728 1~3w \u5de6\u53f3\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n Nginx \u7684\u8fdb\u7a0b\u6a21\u578b<\/strong><\/div>\n <\/p>\n Nginx \u670d\u52a1\u5668\uff0c\u6b63\u5e38\u8fd0\u884c\u8fc7\u7a0b\u4e2d<\/strong><\/div>\n 1.\u591a\u8fdb\u7a0b\uff1a\u4e00\u4e2a Master \u8fdb\u7a0b\u3001\u591a\u4e2a Worker \u8fdb\u7a0b \u601d\u8003\uff1a<\/strong><\/div>\n 1.\u8bf7\u6c42\u662f\u8fde\u63a5\u5230 Nginx\uff0cMaster \u8fdb\u7a0b\u8d1f\u8d23\u5904\u7406\u548c\u8f6c\u53d1\uff1f HTTP \u8fde\u63a5\u5efa\u7acb\u548c\u8bf7\u6c42\u5904\u7406\u8fc7\u7a0b<\/strong><\/div>\n 1.Nginx \u542f\u52a8\u65f6\uff0cMaster \u8fdb\u7a0b\uff0c\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6 Nginx \u9ad8\u6027\u80fd\u3001\u9ad8\u5e76\u53d1<\/strong><\/div>\n 1.Nginx \u91c7\u7528\uff1a\u591a\u8fdb\u7a0b + \u5f02\u6b65\u975e\u963b\u585e\u65b9\u5f0f\uff08IO \u591a\u8def\u590d\u7528 epoll\uff09 Nginx \u7684\u4e8b\u4ef6\u5904\u7406\u6a21\u578b<\/strong><\/div>\n request\uff1aNginx \u4e2d http \u8bf7\u6c42\u3002<\/p>\n \u57fa\u672c\u7684 HTTP Web Server \u5de5\u4f5c\u6a21\u5f0f\uff1a<\/p>\n 1.\u63a5\u6536\u8bf7\u6c42\uff1a\u9010\u884c\u8bfb\u53d6\u8bf7\u6c42\u884c\u548c\u8bf7\u6c42\u5934\uff0c\u5224\u65ad\u6bb5\u6709\u8bf7\u6c42\u4f53\u540e\uff0c\u8bfb\u53d6\u8bf7\u6c42\u4f53 <\/p>\n \u6a21\u5757\u5316\u4f53\u7cfb\u7ed3\u6784<\/strong><\/div>\n <\/p>\n nginx\u7684\u6a21\u5757\u6839\u636e\u5176\u529f\u80fd\u57fa\u672c\u4e0a\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u51e0\u79cd\u7c7b\u578b\uff1a<\/strong><\/div>\n 1.event module: \u642d\u5efa\u4e86\u72ec\u7acb\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e8b\u4ef6\u5904\u7406\u673a\u5236\u7684\u6846\u67b6\uff0c\u53ca\u63d0\u4f9b\u4e86\u5404\u5177\u4f53\u4e8b\u4ef6\u7684\u5904\u7406\u3002\u5305\u62ecngx_events_module\uff0c ngx_event_core_module\u548cngx_epoll_module\u7b49\u3002nginx\u5177\u4f53\u4f7f\u7528\u4f55\u79cd\u4e8b\u4ef6\u5904\u7406\u6a21\u5757\uff0c\u8fd9\u4f9d\u8d56\u4e8e\u5177\u4f53\u7684\u64cd\u4f5c\u7cfb\u7edf\u548c\u7f16\u8bd1\u9009\u9879\u3002 \u5e38\u89c1\u95ee\u9898\u5256\u6790 \nNginx vs. Apache \n<\/strong><\/div>\n \u7f51\u7edc IO \u6a21\u578b\uff1a<\/p>\n 1.nginx\uff1aIO \u591a\u8def\u590d\u7528\uff0cepoll(freebsd \u4e0a\u662f kqueue ) \u573a\u666f\uff1a<\/strong><\/div>\n \u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u65f6\uff0c\u53ef\u4ee5\u91c7\u7528\uff1aIO \u591a\u8def\u590d\u7528 \u6216\u8005 \u963b\u585e IO +\u591a\u7ebf\u7a0b<\/p>\n IO \u591a\u8def\u670d\u7528\uff1a\u4e00\u4e2a \u7ebf\u7a0b\uff0c\u8ddf\u8e2a\u591a\u4e2a socket \u72b6\u6001\uff0c\u54ea\u4e2a\u5c31\u7eea\uff0c\u5c31\u8bfb\u5199\u54ea\u4e2a\uff1b \u601d\u8003\uff1aIO \u591a\u8def\u590d\u7528 \u548c \u591a\u7ebf\u7a0b \u7684\u9002\u7528\u573a\u666f\uff1f<\/strong><\/div>\n IO \u591a\u8def\u590d\u7528\uff1a\u5355\u4e2a\u8fde\u63a5\u7684\u8bf7\u6c42\u5904\u7406\u901f\u5ea6\u6ca1\u6709\u4f18\u52bf\uff0c\u9002\u5408 IO \u5bc6\u96c6\u578b \u573a\u666f\uff0c\u4e8b\u4ef6\u9a71\u52a8 Nginx \u6700\u5927\u8fde\u63a5\u6570<\/strong><\/div>\n \u57fa\u7840\u80cc\u666f\uff1a<\/strong><\/span><\/div>\n 1.Nginx \u662f\u591a\u8fdb\u7a0b\u6a21\u578b\uff0cWorker \u8fdb\u7a0b\u7528\u4e8e\u5904\u7406\u8bf7\u6c42\uff1b \u56e0\u6b64\uff0cNginx \u7684\u6700\u5927\u8fde\u63a5\u6570\uff1a<\/strong><\/span><\/div>\n 1.Nginx \u7684\u6700\u5927\u8fde\u63a5\u6570\uff1aWorker \u8fdb\u7a0b\u6570\u91cf x \u5355\u4e2a Worker \u8fdb\u7a0b\u7684\u6700\u5927\u8fde\u63a5\u6570 \u601d\u8003\uff1a<\/strong><\/div>\n \u6bcf\u6253\u5f00\u4e00\u4e2a socket \u5360\u7528\u4e00\u4e2a fd<\/p>\n \u4e3a\u4ec0\u4e48\uff0c\u4e00\u4e2a\u8fdb\u7a0b\u80fd\u591f\u6253\u5f00\u7684 fd \u6570\u91cf\u6709\u9650\u5236\uff1f<\/p>\n IO \u6a21\u578b<\/strong><\/div>\n \u573a\u666f\uff1a<\/strong><\/span><\/div>\n \u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u65f6\uff0c\u53ef\u4ee5\u91c7\u7528\uff1aIO \u591a\u8def\u590d\u7528 \u6216\u8005 \u963b\u585e IO +\u591a\u7ebf\u7a0b<\/p>\n IO \u591a\u8def\u590d\u7528\uff1a\u4e00\u4e2a \u7ebf\u7a0b\uff0c\u8ddf\u8e2a\u591a\u4e2a socket \u72b6\u6001\uff0c\u54ea\u4e2a\u5c31\u7eea\uff0c\u5c31\u8bfb\u5199\u54ea\u4e2a\uff1b \u601d\u8003\uff1a \nIO \u591a\u8def\u590d\u7528 \u548c \u591a\u7ebf\u7a0b \u7684\u9002\u7528\u573a\u666f\uff1f \n<\/strong><\/span><\/div>\n IO \u591a\u8def\u590d\u7528\uff1a\u5355\u4e2a\u8fde\u63a5\u7684\u8bf7\u6c42\u5904\u7406\u901f\u5ea6\u6ca1\u6709\u4f18\u52bf select\/poll \u548c epoll \u6bd4\u8f83<\/strong><\/div>\n \u8be6\u7ec6\u5185\u5bb9\uff0c\u53c2\u8003\uff1a<\/p>\n select poll epoll\u4e09\u8005\u4e4b\u95f4\u7684\u6bd4\u8f83<\/strong><\/span><\/div>\n select\/poll \u7cfb\u7edf\u8c03\u7528\uff1a<\/p>\n \/\/ select \u7cfb\u7edf\u8c03\u7528 \r\n \r\nint select(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval *timeout); \r\n \r\n\/\/ poll \u7cfb\u7edf\u8c03\u7528 \r\n \r\nint poll(struct pollfd fds[], nfds_t nfds, int timeout)\uff1b<\/pre>\n |