{"id":892,"date":"2022-07-07T17:39:57","date_gmt":"2022-07-07T09:39:57","guid":{"rendered":"http:\/\/www.rchen.top\/?p=892"},"modified":"2022-07-07T17:39:58","modified_gmt":"2022-07-07T09:39:58","slug":"nginx%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%90%ad%e5%bb%ba%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/www.rchen.top\/?p=892","title":{"rendered":"nginx\u670d\u52a1\u5668\u642d\u5efa\u7b14\u8bb0"},"content":{"rendered":"<p>yum\u90e8\u7f72\u65b9\u6cd5<\/p>\n<p>\u64cd\u4f5c\u7cfb\u7edf\uff1aCentOS 7<\/p>\n<table>\n<tbody>\n<tr>\n<td>setenforce 0<\/p>\n<p>systemctl stop iptables.service<\/p>\n<p>systemctl stop firewalld.service<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5b89\u88c5 Nginx \u6839\u636e\u559c\u597d\u9009\u62e9\u5b89\u88c5\u65b9\u5f0f\u548c\u7248\u672c<\/p>\n<table>\n<tbody>\n<tr>\n<td>wget <a href=\"http:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\">http:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm<\/a><\/p>\n<p>rpm -ivh epel-release-latest-7.noarch.rpm<\/p>\n<p>yum -y install nginx<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u51c6\u5907\u914d\u7f6e\u6587\u4ef6 \u4fee\u6539 \/etc\/nginx\/nginx.conf<\/p>\n<p>\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p>$ vim \/etc\/nginx\/nginx.conf<\/p>\n<p>&#8230; \u914d\u7f6e\u7701\u7565<\/p>\n<p>\u8fd0\u884c Nginx\uff0c# \u786e\u4fdd\u914d\u7f6e\u6ca1\u6709\u95ee\u9898, \u6709\u95ee\u9898\u8bf7\u5148\u89e3\u51b3<\/p>\n<p>nginx -t<\/p>\n<p>\u542f\u52a8\u670d\u52a1<\/p>\n<p>systemctl start nginx<\/p>\n<p>systemctl restart nginx<\/p>\n<p>systemctl stop nginx<\/p>\n<p>systemctl enable nginx<\/p>\n<p>\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e<\/p>\n<p>nginx -s reload<\/p>\n<p>\u6216\u8005<\/p>\n<p>\/usr\/local\/nginx\/sbin\/nginx -s reload<\/p>\n<p>\u7f16\u8bd1\u90e8\u7f72\u65b9\u6cd5<\/p>\n<p><b>\u8f6f\u4ef6\u9700\u8981\u7f16\u8bd1\u5b89\u88c5\u7684\u771f\u5b9e\u7406\u7531\u6709\u5982\u4e0b3\u70b9\uff1a<\/b><\/p>\n<ol>\n<li>\u8f6f\u4ef6\u5728\u7f16\u8bd1\u671f\u95f4\u9700\u8981\u914d\u7f6e\uff0c\u6bd4\u5982\u8bf4nginx\uff0c\u9700\u8981\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u6307\u5b9a\u5305\u542b\u54ea\u4e9bmodule\uff0cphp,apache \u4e5f\u662f\u4e00\u6837\u3002\u540c\u6837\u7684\u662f\u6570\u636e\u5e93\uff0cmysql \u901a\u8fc7\u7f16\u8bd1\u5b89\u88c5\uff0c\u56e0\u4e3a\u8981\u5b9a\u5236\u5b58\u50a8\u5f15\u64ce\uff08\u662f\u5426\u652f\u6301innodb .. \uff09,\u800csqlite\u5374\u7edd\u5c11\u6709\u4eba\u7f16\u8bd1\uff0c\u90fd\u662f\u76f4\u63a5\u4e0b\u8f7d\u4e8c\u8fdb\u5236\u6587\u4ef6\u6765\u7528\u3002<\/li>\n<li>\u8f6f\u4ef6\u9700\u8981\u7edf\u4e00\u5b89\u88c5\u8def\u5f84\uff0c\u6bcf\u4e2ateam\u90fd\u4f1a\u81ea\u5df1\u7684\u5b89\u88c5\u76ee\u5f55\u7ea6\u5b9a\uff0c\u6709\u4e9b\u559c\u6b22\u88c5\u5728 \/opt\/\u4e0b\u9762\uff0c\u6709\u4e9b\u559c\u6b22\u88c5\u5728 \/usr\/local\/ ,\u7f16\u8bd1\u5b89\u88c5\u53ef\u4ee5\u65b9\u4fbf\u7684\u6307\u5b9a\u8fd9\u4e9b\u8def\u5f84\uff08configure \u2013prefix=xxx \uff09<\/li>\n<li>\u9700\u8981\u6700\u65b0\u7684\u7248\u672c\uff0c\u8f6f\u4ef6\u4ed3\u5e93\u7684\u7248\u672c\u4e00\u822c\u90fd\u6bd4\u8f83\u4f4e\uff0c\u8fd9\u4e2a\u7406\u7531\u5176\u5b9e\u4e0d\u5145\u5206\uff0c\u751f\u4ea7\u73af\u5883\u503e\u5411\u4fdd\u5b88\uff0c\u4e0d\u8ffd\u6c42\u6700\u65b0\u7248\u672c\uff0c\u4f46\u662f\u5bf9\u4e8egeek\u6765\u8bf4\uff0c\u8fd9\u53ef\u80fd\u662f\u6700\u91cd\u8981\u7684\u539f\u56e0<\/li>\n<\/ol>\n<p><b>\u6b63\u5f0f\u5b89\u88c5\u6b65\u9aa4\uff1a<\/b><\/p>\n<p><b>1\u3001\u73af\u5883\u51c6\u5907\uff1a\u5148\u5b89\u88c5\u51c6\u5907\u73af\u5883<\/b><\/p>\n<p>yum -y install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel<\/p>\n<p><b>2\u3001\u4e0b\u8f7dnginx \u5b89\u88c5\u5305\uff1a\u00a0 <\/b><\/p>\n<p><b>\u5b98\u7f51\u5730\u5740\uff1a <\/b><a href=\"http:\/\/nginx.org\/\"><b>http:\/\/nginx.org\/<\/b><\/a><\/p>\n<p><b>3\u3001<\/b><b>\u4e0a\u4f20\u670d\u52a1\u3001<\/b><b>\u89e3\u538b\u5b89\u88c5\u5305:<\/b><\/p>\n<p>tar\u00a0 xvf nginx-1.8.1.tar.gz<\/p>\n<p>cd nginx-1.8.1<\/p>\n<p>ls<\/p>\n<p>auto\u00a0 CHANGES\u00a0 CHANGES.ru\u00a0 conf\u00a0 configure\u00a0 contrib\u00a0 html\u00a0 LICENSE\u00a0 man\u00a0 README\u00a0 src<\/p>\n<p><b>4\u3001\u7f16\u8bd1nginx\uff1amake<\/b><\/p>\n<p>\u7f16\u8bd1\u662f\u4e3a\u4e86\u68c0\u67e5\u7cfb\u7edf\u73af\u5883\u662f\u5426\u7b26\u5408\u7f16\u8bd1\u5b89\u88c5\u7684\u8981\u6c42\uff0c\u6bd4\u5982\u662f\u5426\u6709gcc\u7f16\u8bd1\u5de5\u5177\uff0c\u662f\u5426\u652f\u6301\u7f16\u8bd1\u53c2\u6570\u5f53\u4e2d\u7684\u6a21\u5757\uff0c\u5e76\u6839\u636e\u5f00\u542f\u7684\u53c2\u6570\u7b49\u751f\u6210Makefile\u6587\u4ef6\u4e3a\u4e0b\u4e00\u6b65\u505a\u51c6\u5907\uff1a<\/p>\n<table>\n<tbody>\n<tr>\n<td>.\/configure\u00a0 &#8211;prefix=\/usr\/local\/nginx\u00a0 &#8211;sbin-path=\/usr\/local\/nginx\/sbin\/nginx &#8211;conf-path=\/usr\/local\/nginx\/conf\/nginx.conf &#8211;error-log-path=\/var\/log\/nginx\/error.log\u00a0 &#8211;http-log-path=\/var\/log\/nginx\/access.log\u00a0 &#8211;pid-path=\/var\/run\/nginx\/nginx.pid &#8211;lock-path=\/var\/lock\/nginx.lock\u00a0 &#8211;user=nginx &#8211;group=nginx &#8211;with-http_ssl_module &#8211;with-http_stub_status_module &#8211;with-http_gzip_static_module &#8211;http-client-body-temp-path=\/var\/tmp\/nginx\/client\/ &#8211;http-proxy-temp-path=\/var\/tmp\/nginx\/proxy\/ &#8211;http-fastcgi-temp-path=\/var\/tmp\/nginx\/fcgi\/ &#8211;http-uwsgi-temp-path=\/var\/tmp\/nginx\/uwsgi &#8211;http-scgi-temp-path=\/var\/tmp\/nginx\/scgi &#8211;with-pcre<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>make &amp;&amp; make install<\/p>\n<p>\u5907\u6ce8\uff1anginx\u5b8c\u6210\u5b89\u88c5\u4ee5\u540e\uff0c\u6709\u56db\u4e2a\u4e3b\u8981\u7684\u76ee\u5f55\uff1a<\/p>\n<p>conf\uff1a\u4fdd\u5b58nginx\u6240\u6709\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u4e2dnginx.conf\u662fnginx\u670d\u52a1\u5668\u7684\u6700\u6838\u5fc3\u6700\u4e3b\u8981\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u4ed6\u7684.conf\u5219\u662f\u7528\u6765\u914d\u7f6enginx\u76f8\u5173\u7684\u529f\u80fd\u7684\uff0c\u4f8b\u5982fastcgi\u529f\u80fd\u4f7f\u7528\u7684\u662ffastcgi.conf\u548cfastcgi_params\u4e24\u4e2a\u6587\u4ef6\uff0c\u914d\u7f6e\u6587\u4ef6\u4e00\u822c\u90fd\u6709\u4e2a\u6837\u677f\u914d\u7f6e\u6587\u4ef6\uff0c\u662f\u6587\u4ef6\u540d.default\u7ed3\u5c3e\uff0c\u4f7f\u7528\u7684\u4f7f\u7528\u5c06\u5176\u590d\u5236\u4e3a\u5e76\u5c06default\u53bb\u6389\u5373\u53ef\u3002<\/p>\n<p>html\u76ee\u5f55\u4e2d\u4fdd\u5b58\u4e86nginx\u670d\u52a1\u5668\u7684web\u6587\u4ef6\uff0c\u4f46\u662f\u53ef\u4ee5\u66f4\u6539\u4e3a\u5176\u4ed6\u76ee\u5f55\u4fdd\u5b58web\u6587\u4ef6,\u53e6\u5916\u8fd8\u6709\u4e00\u4e2a50x\u7684web\u6587\u4ef6\u662f\u9ed8\u8ba4\u7684\u9519\u8bef\u9875\u9762\u63d0\u793a\u9875\u9762\u3002<\/p>\n<p>logs\uff1a\u7528\u6765\u4fdd\u5b58nginx\u670d\u52a1\u5668\u7684\u8bbf\u95ee\u65e5\u5fd7\u9519\u8bef\u65e5\u5fd7\u7b49\u65e5\u5fd7\uff0clogs\u76ee\u5f55\u53ef\u4ee5\u653e\u5728\u5176\u4ed6\u8def\u5f84\uff0c\u6bd4\u5982\/var\/logs\/nginx\u91cc\u9762\u3002<\/p>\n<p>sbin\uff1a\u4fdd\u5b58nginx\u4e8c\u8fdb\u5236\u542f\u52a8\u811a\u672c\uff0c\u53ef\u4ee5\u63a5\u53d7\u4e0d\u540c\u7684\u53c2\u6570\u4ee5\u5b9e\u73b0\u4e0d\u540c\u7684\u529f\u80fd\u3002<\/p>\n<p><b>5<\/b><b>\u3001\u542f\u52a8\u3001\u62a5\u9519\u3001\u89e3\u51b3<\/b><\/p>\n<p>\u95ee\u98981<\/p>\n<p>[root@Wordpress sbin]# \/usr\/local\/nginx\/sbin\/nginx<\/p>\n<p>nginx: [emerg] getpwnam(&#8220;nginx&#8221;) failed<\/p>\n<p>\u89e3\u51b3\u65b9\u68482<\/p>\n<p>[root@Wordpress sbin]# useradd -s \/sbin\/nologin -M nginx<\/p>\n<p>[root@Wordpress sbin]# id nginx<\/p>\n<p>uid=1001(nginx) gid=1001(nginx) \u7ec4=1001(nginx)<\/p>\n<p>\u95ee\u98982<\/p>\n<p>[root@Wordpress sbin]# \/usr\/local\/nginx\/sbin\/nginx<\/p>\n<p>nginx: [emerg] mkdir() &#8220;\/var\/tmp\/nginx\/client\/&#8221; failed (2: No such file or directory)<\/p>\n<p>\u89e3\u51b3\u65b9\u68482<\/p>\n<p>[root@Wordpress sbin]# mkdir \/var\/tmp\/nginx<\/p>\n<p>\u95ee\u98983<\/p>\n<p>[root@Wordpress conf]# \/usr\/local\/nginx\/sbin\/nginx -t<\/p>\n<p>nginx: [error] open() &#8220;\/usr\/local\/nginx\/logs\/nginx.pid&#8221; failed (2: No such file or directory)<\/p>\n<p>\u89e3\u51b3\u65b9\u68483<\/p>\n<p>\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6nginx.conf \uff1b<\/p>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6709\u4e2a\u6ce8\u91ca\u7684\u5730\u65b9\uff1a #pid logs\/nginx.pid;\u5c06\u6ce8\u91ca\u653e\u5f00\uff0c\u5e76\u4fee\u6539\u4e3a\uff1apid\u00a0 \/usr\/local\/nginx\/logs\/nginx.pid;<\/p>\n<p>\u5728 \/usr\/local\/nginx \u76ee\u5f55\u4e0b\u521b\u5efa logs \u76ee\u5f55\uff1amkdir \/usr\/local\/nginx\/logs\/<\/p>\n<table>\n<tbody>\n<tr>\n<td>\/usr\/local\/nginx\/sbin\/nginx\u00a0 \u00a0#\u542f\u52a8 \u670d\u52a1<\/p>\n<p>\/usr\/local\/nginx\/sbin\/nginx\u00a0\u00a0 -s\u00a0 reload\u00a0 #\u4e0d\u505c\u6b62\u670d\u52a1\u91cd\u8bfb\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>\/usr\/local\/nginx\/sbin\/nginx -s stop #\u505c\u6b62\u670d\u52a1\u00a0 #\u505c\u6b62\u670d\u52a1<\/p>\n<p>\/usr\/local\/nginx\/sbin\/nginx -t\u00a0 #\u68c0\u67e5\u542f\u52a8\u662f\u5426\u6b63\u5e38<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>6<\/b><b>\u3001<\/b><b>\u52a0\u5165systemctl\u7ba1\u7406\u670d\u52a1<\/b><\/p>\n<ul>\n<li>\u8fdb\u5165\u5230\u00a0 \/usr\/lib\/systemd\/system \u76ee\u5f55\u4e0b\uff0c\u7f16\u8f91\u6587\u4ef6 nginx.service<\/li>\n<li>\u5728nginx.service\u6587\u4ef6\u4e2d\u52a0\u5165\u4ee5\u4e0b\u4ee3\u7801<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td>[Unit]<\/p>\n<p>Description=nginx<\/p>\n<p>After=network.target<\/p>\n<p>[Service]<\/p>\n<p>Type=forking<\/p>\n<p>ExecStart=\/usr\/local\/nginx\/sbin\/nginx<\/p>\n<p>ExecReload=\/usr\/local\/nginx\/sbin\/nginx -s reload<\/p>\n<p>ExecStop=\/usr\/local\/nginx\/sbin\/nginx -s stop<\/p>\n<p>PrivateTmp=true<\/p>\n<p>[Install]<\/p>\n<p>WantedBy=multi-user.target<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>\u4f7f\u65b0\u6ce8\u518c\u670d\u52a1\u751f\u6548<\/b><\/p>\n<p>systemctl daemon-reload<\/p>\n","protected":false},"excerpt":{"rendered":"<p>yum\u90e8\u7f72\u65b9\u6cd5 \u64cd\u4f5c\u7cfb\u7edf\uff1aCentOS 7 setenforce 0 systemctl stop iptab [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":889,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[95],"tags":[145],"class_list":["post-892","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-95","tag-nginx"],"_links":{"self":[{"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/posts\/892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=892"}],"version-history":[{"count":1,"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/posts\/892\/revisions"}],"predecessor-version":[{"id":893,"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/posts\/892\/revisions\/893"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=\/wp\/v2\/media\/889"}],"wp:attachment":[{"href":"https:\/\/www.rchen.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rchen.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}