{"id":158,"date":"2021-03-01T20:12:53","date_gmt":"2021-03-01T12:12:53","guid":{"rendered":"http:\/\/www.hufe.org.cn\/?p=158"},"modified":"2021-03-01T20:12:53","modified_gmt":"2021-03-01T12:12:53","slug":"centos7%e4%b8%8b%e5%ae%89%e8%a3%85nginx%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.hufe.org.cn\/?p=158","title":{"rendered":"Centos7\u4e0b\u5b89\u88c5Nginx\u6559\u7a0b"},"content":{"rendered":"<p>\u7531\u4e8e\u9879\u76ee\u8fc1\u79fb\u81f3.NetCore \u505a\u5206\u5e03\u5f0f\u670d\u52a1\uff0cOcelot\u548cNginx\u4e4b\u95f4\u9009\u62e9\u6700\u540e\u4f7f\u7528\u4e86Nginx\u4f5c\u4e3a\u7f51\u5173\u548c\u8d1f\u8f7d\u5747\u8861\u670d\u52a1\uff0c\u4e0b\u9762\u7b80\u8ff0Nginx\u5b89\u88c5\u6559\u7a0b\uff0c\u540e\u671f\u9646\u7eed\u628a\u8d1f\u8f7d\u5747\u8861\uff0c\u8def\u8def\u7531\u91cd\u5199\uff0c\u9650\u6d41 \u5065\u5eb7\u68c0\u67e5\u7b49\u914d\u7f6e\u5199\u51fa\u6765 \u672c\u6b21\u4f7f\u7528\u73af\u5883\u4e3aCentos7\u3002<\/p>\n<p>Nginx\u7b80\u4ecb<br \/>\nNginx\u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684HTTP\u548c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u4e5f\u662f\u4e00\u4e2aIMAP\/POP3\/SMTP\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u56e0\u5b83\u7684\u7a33\u5b9a\u6027,\u4e30\u5bcc\u7684\u529f\u80fd\u96c6\uff0c\u914d\u7f6e\u7b80\u5355\u548c\u4f4e\u7cfb\u7edf\u8d44\u6e90\u7684\u6d88\u8017\u800c\u95fb\u540d<\/p>\n<p>Nginx\u7684\u6700\u5927\u7279\u70b9\u662f\u662f\u5bf9\u9ad8\u5e76\u53d1\u7684\u652f\u6301\u548c\u9ad8\u6548\u7684\u8d1f\u8f7d\u5747\u8861<br \/>\n\u56fe\u72471.png<br \/>\nNginx\u7684\u7279\u70b9<\/p>\n<p>\u2022\u70ed\u90e8\u7f72<\/p>\n<p>master\u7ba1\u7406\u8fdb\u7a0b\u4e0eworker\u5de5\u4f5c\u8fdb\u7a0b\u7684\u5206\u79bb\u8bbe\u8ba1,\u57287*24\u5c0f\u65f6\u4e0d\u95f4\u65ad\u7684\u524d\u63d0\u4e0b,\u5347\u7ea7nginx\u7684\u53ef\u6267\u884c\u6587\u4ef6,\u4e5f\u53ef\u4ee5\u5728\u4e0d\u505c\u6b62\u670d\u52a1\u7684\u60c5\u51b5\u4e0b\u4fee\u6539\u914d\u7f6e\u6587\u4ef6,\u66f4\u6362\u65e5\u5fd7\u6587\u4ef6\u7b49\u5185\u5bb9<\/p>\n<p>\u2022\u9ad8\u5e76\u53d1\u8fde\u63a5<\/p>\n<p>\u5b98\u65b9\u6d4b\u8bd5\u5355\u53f0nginx\u80fd\u591f\u652f\u64915\u4e07\u5e76\u53d1\u8fde\u63a5,\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\u53ef \u4ee5\u8fbe\u52302-3\u4e07\u5e76\u53d1\u8fde\u63a5<\/p>\n<p>\u2022\u5185\u5b58\u6d88\u8017\u5c11<\/p>\n<p>\u5728\u4e00\u822c\u60c5\u51b5\u4e0b,10000\u4e2a\u975e\u6d3b\u8dc3\u7684HTTP keep-Alive\u8fde\u63a5\u5728Nginx\u4e2d\u4ec5\u6d88\u80172.5M\u5185\u5b58,\u8fd9\u662fNginx\u652f\u6301\u9ad8\u5e76\u53d1\u8fde\u63a5\u7684\u57fa\u7840<\/p>\n<p>\u2022\u652f\u6301Rewrite\u91cd\u5199\u89c4\u5219<\/p>\n<p>\u80fd\u591f\u6839\u636e\u57df\u540dURL\u7684\u4e0d\u540c,\u5c06HTTP\u8bf7\u6c42\u5206\u53d1\u5230\u4e0d\u540c\u7684\u540e\u7aef\u670d\u52a1\u5668\u7fa4\u7ec4<\/p>\n<p>\u2022\u6210\u672c\u4f4e\u5ec9<\/p>\n<p>Nginx\u4f5c\u4e3a\u5f00\u6e90\u514d\u8d39\u8f6f\u4ef6,\u53ef\u4ee5\u514d\u8d39\u4f7f\u7528<\/p>\n<p>**\u2022\u5185\u7f6e\u7684\u5065\u5eb7\u68c0\u67e5 **<\/p>\n<p>\u5982\u679cNginx Proxy\u540e\u7aef\u7684\u67d0\u53f0Web\u670d\u52a1\u5b95\u673a\u4e86,\u4e0d\u4f1a\u5f71\u54cd\u524d\u7aef\u7684\u8bbf\u95ee<\/p>\n<p>Nginx\u7684\u5b89\u88c5<\/p>\n<p>\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c<\/p>\n<p>\u4e00\u3001\u5b89\u88c5\u4f9d\u8d56 nginx\u5b89\u88c5\u9700\u8981\u4ece\u5b98\u7f51\u4e0b\u8f7d\u6e90\u7801\u8fdb\u884c\u7f16\u8bd1\uff0c\u6240\u4ee5\u8981\u4f9d\u8d56\u4e00\u4e9b\u7f16\u8bd1\u73af\u5883\u3002<\/p>\n<p>    \/\/\u7f16\u8bd1\u4f9d\u8d56gcc\u73af\u5883<br \/>\n    .yum install gcc  <\/p>\n<p>    \/\/ nginx\u7684http\u6a21\u5757\u4f7f\u7528pcre\u6765\u89e3\u6790\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u6240\u4ee5\u9700\u8981\u5728linux\u4e0a<br \/>\n    \u5b89\u88c5pcre\u5e93<br \/>\n    .yum install pcre-devel   <\/p>\n<p>    \/\/ zlib\u5e93\u63d0\u4f9b\u4e86\u5f88\u591a\u79cd\u538b\u7f29\u548c\u89e3\u538b\u7f29\u7684\u65b9\u5f0f\uff0cnginx\u4f7f\u7528zlib\u5bf9http\u5305<br \/>\n    \u7684\u5185\u5bb9\u8fdb\u884cgzip\uff0c\u6240\u4ee5\u9700\u8981\u5728linux\u4e0a\u5b89\u88c5zlib\u5e93\u3002<br \/>\n    .yum install zlib zlib-devel   <\/p>\n<p>    \/\/OpenSSL \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5b89\u5168\u5957\u63a5\u5b57\u5c42\u5bc6\u7801\u5e93\uff0c\u56ca\u62ec\u4e3b\u8981\u7684\u5bc6\u7801<br \/>\n    \u7b97\u6cd5\u3001\u5e38\u7528\u7684\u5bc6\u94a5\u548c\u8bc1\u4e66\u5c01\u88c5\u7ba1\u7406\u529f\u80fd\u53caSSL\u534f\u8bae\uff0c\u5e76\u63d0\u4f9b\u4e30\u5bcc\u7684<br \/>\n    \u5e94\u7528\u7a0b\u5e8f\u4f9b\u6d4b\u8bd5\u6216\u5176\u5b83\u76ee\u7684\u4f7f\u7528,nginx\u4e0d\u4ec5\u652f\u6301http\u534f\u8bae\uff0c\u8fd8\u652f\u6301<br \/>\n    https\uff08\u5373\u5728ssl\u534f\u8bae\u4e0a\u4f20\u8f93http\uff09\uff0c\u6240\u4ee5\u9700\u8981\u5728linux\u5b89\u88c5openssl<br \/>\n    \u5e93\u3002<br \/>\n    .yum install openssl openssl-devel <\/p>\n<p>\u4e00\u952e\u5b89\u88c5\u6240\u9700\u8981\u7684\u4f9d\u8d56\u5e93<br \/>\n yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel pcre&#8220;&#8220;<br \/>\n\u4e8c\u3001\u4e0b\u8f7d\u548c\u89e3\u538bnginx<\/p>\n<p>   cd \/usr\/local  \/\/\u8fdb\u5165local\u76ee\u5f55<\/p>\n<p>   mkdir nginx  \/\/\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939<\/p>\n<p>   cd nginx   \/\/\u8fdb\u5165nginx\u76ee\u5f55<\/p>\n<p>   \/\/\u4e0b\u8f7dtar\u5305<br \/>\n   wget http:\/\/nginx.org\/download\/nginx-1.13.7.tar.gz<br \/>\n  \/\/\u89e3\u538b<br \/>\n   tar -zxvf nginx-1.13.7.tar.gz<br \/>\n\u4e09\u3001\u5b89\u88c5 nginx<\/p>\n<p>  \/\/\u8fdb\u5165nginx\u89e3\u538b\u76ee\u5f55<br \/>\n  cd \/usr\/local\/nginx\/nginx-1.13.7<\/p>\n<p>  \/\/\u914d\u7f6e \u6267\u884c\u547d\u4ee4 &#8211;prefix \u7ed1\u5b9a\u5b89\u88c5\u76ee\u5f55  \u5b89\u88c5\u76ee\u5f55\u53ef\u4ee5\u81ea\u5df1\u6307\u5b9a\u53ef<br \/>\n  \u4ee5\u548c\u4e0b\u8f7d\u76ee\u5f55\u4e0d\u540c\uff0c\u8fd9\u91cc\u5236\u5b9a\u4e3a\/usr\/local\/nginx   \u4e0d\u5199 &#8211;prefix= \u4f1a<br \/>\n  \u4f7f\u7528\u9ed8\u8ba4\u5b89\u88c5\u76ee\u5f55<br \/>\n  .\/configure &#8211;prefix=\/usr\/local\/nginx <\/p>\n<p>  \/\/\u6267\u884cmake\u547d\u4ee4  \u7f16\u8bd1<br \/>\n  make<\/p>\n<p>  \/\/\u6267\u884cmake install\u547d\u4ee4  \u5b89\u88c5<br \/>\n  make install<br \/>\n\u56db\u3001\u67e5\u770b\u5b89\u88c5\u8def\u5f84\u5e76\u8fdb\u5165<\/p>\n<p>  [root@localhost nginx-1.13.7]# whereis nginx<br \/>\n  nginx: \/usr\/local\/nginx<br \/>\n  \/\/\u8fdb\u5165nginx\u5b89\u88c5\u76ee\u5f55<br \/>\n  [root@localhost nginx-1.13.7]# cd \/usr\/local\/nginx<br \/>\n\u4e94.\u5b89\u88c5\u5b8c\u6210\u542f\u52a8\u6d4b\u8bd5<\/p>\n<p> \/\/\u8fdb\u5165nginx\u6267\u884c\u76ee\u5f55<br \/>\ncd sbin<br \/>\n\/\/\u542f\u52a8Nginx<br \/>\nsudo .\/nginx<br \/>\n\u7531\u4e8eCenots\u64cd\u4f5c\u7cfb\u7edf\u539f\u56e0\u9700\u8981\u628anginx\u76d1\u542c\u76ee\u5f55\u5728\u9632\u706b\u5899\u5185\u914d\u7f6e \u8fd9\u91cc<br \/>\n\u76f4\u63a5\u5173\u95ed\u64cd\u4f5c\u7cfb\u7edf\u9632\u706b\u5899<br \/>\nsystemctl stop firewalld.service<br \/>\nnginx\u9ed8\u8ba4\u76d1\u542c\u7aef\u53e3\u4e3a80<br \/>\n\u6b64\u65f6\u5728windows\u5185\u7f51\u7535\u8111\u4e0a\u8bbf\u95eeip:80\u7aef\u53e3\u4f1a\u51fa\u73b0Nginx\u9ed8\u8ba4\u754c\u9762 \u6216\u8005\u5728Linux\u7684\u56fe\u5f62\u754c\u9762\u6d4f\u89c8\u4e0a\u8f93\u5165locashost<\/p>\n<p>2.png<br \/>\n\u8868\u793aNginx\u5b89\u88c5\u6210\u529f<\/p>\n<p>nginx\u7684\u57fa\u672c\u64cd\u4f5c<\/p>\n<p>\u542f\u52a8 [root@localhost ~]# \/usr\/local\/nginx\/sbin\/nginx <\/p>\n<p>\u505c\u6b62\/\u91cd\u542f [root@localhost ~]# \/usr\/local\/nginx\/sbin\/nginx -s stop(quit\u3001reload) <\/p>\n<p>\u547d\u4ee4\u5e2e\u52a9 [root@localhost ~]# \/usr\/local\/nginx\/sbin\/nginx -h <\/p>\n<p>\u9a8c\u8bc1\u914d\u7f6e\u6587\u4ef6 [root@localhost ~]# \/usr\/local\/nginx\/sbin\/nginx -t <\/p>\n<p>\u914d\u7f6e\u6587\u4ef6 [root@localhost ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf<br \/>\n\u4e0b\u7bc7\u4f1a\u4ecb\u7ecdnginx\u7684\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>\u4f5c\u8005\uff1aalways_in<br \/>\n\u94fe\u63a5\uff1ahttps:\/\/www.jianshu.com\/p\/3b29aeec5d0e<br \/>\n\u6765\u6e90\uff1a\u7b80\u4e66<br \/>\n\u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\u3002\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743\uff0c\u975e\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u4e8e\u9879\u76ee\u8fc1\u79fb\u81f3.NetCore \u505a\u5206\u5e03\u5f0f\u670d\u52a1\uff0cOcelot\u548cNginx\u4e4b\u95f4\u9009\u62e9\u6700\u540e\u4f7f\u7528\u4e86Nginx\u4f5c\u4e3a\u7f51\u5173\u548c\u8d1f&hellip;&nbsp;<a href=\"https:\/\/www.hufe.org.cn\/?p=158\" class=\"\" rel=\"bookmark\">\u9605\u8bfb\u66f4\u591a &raquo;<span class=\"screen-reader-text\">Centos7\u4e0b\u5b89\u88c5Nginx\u6559\u7a0b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/158"}],"collection":[{"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":1,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions\/159"}],"wp:attachment":[{"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}