{"id":323,"date":"2021-07-28T14:40:08","date_gmt":"2021-07-28T06:40:08","guid":{"rendered":"http:\/\/egonlin.com\/?p=323"},"modified":"2024-04-01T22:18:22","modified_gmt":"2024-04-01T14:18:22","slug":"%e7%ac%ac%e4%b8%80%e8%8a%82%ef%bc%9alnmp%e6%9e%b6%e6%9e%84%e6%90%ad%e5%bb%ba","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=323","title":{"rendered":"\u7b2c\u4e00\u8282\uff1alnmp\u67b6\u6784\u642d\u5efa"},"content":{"rendered":"<h2>\u4e00\u3001nginx\u6a21\u5757<\/h2>\n<h3>1.\u76ee\u5f55\u7d22\u5f15\u6a21\u5757<\/h3>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \nserver {\n    listen 80;\n    server_name www.autoindex.com;\n    charset utf8;\n\n    location \/ {\n        root \/code\/autoindex;           #\u67e5\u627e\/code\/autoindex\/index.html\n        index index.html;\n    }\n\n    location \/download {\n        root \/code\/autoindex;           #\u67e5\u627e\/code\/autoindex\/download\n        autoindex on;\n    }\n}<\/code><\/pre>\n<h3>2.\u8bbf\u95ee\u9650\u5236\u6a21\u5757<\/h3>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">Syntax: allow address | CIDR | unix: | all;\nDefault:    \u2014\nContext:    http, server, location, limit_except\n\nSyntax: deny address | CIDR | unix: | all;\nDefault:    \u2014\nContext:    http, server, location, limit_except<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">#\u5141\u8bb810.0.0.1\u8bbf\u95ee\uff0c\u62d2\u7edd\u6240\u6709\n[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \nserver {\n    listen 80;\n    server_name www.autoindex.com;\n    charset utf8;\n    access_log \/var\/log\/nginx\/www.autoindex.com.log main;\n\n    location \/ {\n        root \/code\/autoindex;\n        index index.html;\n    }\n\n    location \/download {\n        root \/code\/autoindex;\n        autoindex on;\n        allow 10.0.0.1\uff1b         #\u5141\u8bb810.0.0.1\u8bbf\u95ee\n        deny all;               #\u62d2\u7edd\u966410.0.0.1\u7684\u5176\u4ed6\u8bbf\u95ee\n    }\n}<\/code><\/pre>\n<h3>3.\u8bbf\u95ee\u63a7\u5236\u6a21\u5757<\/h3>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">Syntax: auth_basic string | off;\nDefault:    auth_basic off;\nContext:    http, server, location, limit_except\n\nSyntax: auth_basic_user_file file;\nDefault:    \u2014\nContext:    http, server, location, limit_except<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e\u5bc6\u7801\u6587\u4ef6<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# htpasswd -c \/etc\/nginx\/auth_basic lhd       #-c \u521b\u5efa\u65b0\u7684\u5bc6\u7801\u6587\u4ef6\uff0c\u8ffd\u52a0\u4e0d\u4f7f\u7528-c\u53c2\u6570\u3002\nNew password: \nRe-type new password: \nAdding password for user lhd<\/code><\/pre>\n<h4>3\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \nserver {\n    listen 80;\n    server_name www.autoindex.com;\n    charset utf8;\n\n    location \/ {\n        root \/code\/autoindex;\n        index index.html;\n    }\n\n    location \/download {\n        root \/code\/autoindex;\n        auth_basic &quot;\u8bf7\u8f93\u5165\u7528\u6237\u540d\u548c\u5bc6\u7801\uff1a&quot;;      #\u5f15\u53f7\u5185\u968f\u4fbf\u8f93\u5165\u5b57\u7b26\u8868\u793a\u6253\u5f00\u8bbf\u95ee\u63a7\u5236\n        auth_basic_user_file \/etc\/nginx\/auth_basic; #\u540e\u9762\u8ddf\u542b\u6709\u7528\u6237\u540d\u548c\u5bc6\u7801\u7684\u6587\u4ef6\n    }\n}<\/code><\/pre>\n<h3>4.nginx\u72b6\u6001\u6a21\u5757<\/h3>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">Syntax: stub_status;\nDefault:    \u2014\nContext:    server, location<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \nserver {\n    listen 80;\n    server_name www.autoindex.com;\n    charset utf8;\n    location \/ {\n        root \/code\/autoindex;\n        index index.html;\n    }\n\n    location = \/basic_status {          #www.autoindex.com\/basic_status\u53ef\u4ee5\u8bbf\u95eenginx\u72b6\u6001\n        stub_status;\n    }\n}<\/code><\/pre>\n<h4>3\uff09\u9875\u9762<\/h4>\n<pre><code class=\"language-bash\">Active connections: 1 \nserver accepts handled requests\n        1       1       1 \nReading: 0 Writing: 1 Waiting: 0 <\/code><\/pre>\n<h4>4\uff09\u76d1\u63a7\u7f51\u7ad9\u7684PV<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# curl -s http:\/\/www.autoindex.com\/basic_status | awk &#039;NR==3 {print $3}&#039;\n61<\/code><\/pre>\n<h3>5.\u8fde\u63a5\u9650\u5236\u6a21\u5757<\/h3>\n<pre><code class=\"language-bash\"># ngx_http_limit_conn_module<\/code><\/pre>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">#\u8bbe\u7f6e\u9650\u5236\u7684\u7a7a\u95f4\nSyntax: limit_conn_zone key zone=name:size;\nDefault:    \u2014\nContext:    http\n\nlimit_conn_zone     #\u8bbe\u7f6e\u7a7a\u95f4\u7684\u6a21\u5757\nkey                 #\u6307\u5b9a\u7a7a\u95f4\u5b58\u50a8\u7684\u5185\u5bb9\nzone                #\u6307\u5b9a\u7a7a\u95f4\n=name               #\u7a7a\u95f4\u540d\u5b57\n:size;              #\u7a7a\u95f4\u7684\u5927\u5c0f\n\n#\u8c03\u7528\u9650\u5236\u7684\u7a7a\u95f4\nSyntax: limit_conn zone number;\nDefault:    \u2014\nContext:    http, server, location\n\nlimit_conn          #\u8c03\u7528\u7a7a\u95f4\u7684\u6a21\u5757\nzone                #\u7a7a\u95f4\u7684\u540d\u5b57\nnumber;             #\u6307\u5b9a\u53ef\u4ee5\u540c\u65f6\u8fde\u63a5\u7684\u6b21\u6570<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \nlimit_conn_zone $remote_addr zone=conn_zone:10m;    #\u8bbe\u7f6e\u4e00\u4e2a\u5b58\u50a8ip\u5730\u5740\uff0c\u7a7a\u95f4\u540d\u5b57\u4e3aconn_zone,\u7a7a\u95f4\u5927\u5c0f\u4e3a10M\u7684\u7a7a\u95f4\nserver {\n    listen 80;\n    server_name www.autoindex.com;\n    charset utf8;;\n    limit_conn conn_zone 1;     #\u8c03\u7528conn_zone\u7a7a\u95f4\uff0c\u9650\u5236\u6bcf\u4e2aip\u540c\u65f6\u53ea\u80fd\u8fde\u63a5\u4e00\u6b21\n\n    location \/ {\n        root \/code\/autoindex;\n        index index.html;\n    }\n}<\/code><\/pre>\n<h3>6.\u8bf7\u6c42\u9650\u5236\u6a21\u5757<\/h3>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">#\u8bbe\u7f6e\u7a7a\u95f4\u7684\u8bed\u6cd5\nSyntax: limit_req_zone key zone=name:size rate=rate [sync];\nDefault:    \u2014\nContext:    http\n\nlimit_req_zone          #\u8bbe\u7f6e\u7a7a\u95f4\u7684\u6a21\u5757\nkey                     #\u7a7a\u95f4\u5b58\u50a8\u7684\u5185\u5bb9\nzone                    #\u6307\u5b9a\u7a7a\u95f4\n=name                   #\u7a7a\u95f4\u7684\u540d\u5b57\n:size                   #\u7a7a\u95f4\u7684\u5927\u5c0f\nrate=rate [sync];       #\u8bfb\u5199\u901f\u7387\n\n#\u8c03\u7528\u7684\u8bed\u6cd5\nSyntax: limit_req zone=name [burst=number] [nodelay | delay=number];\nDefault:    \u2014\nContext:    http, server, location\n\nlimit_req               #\u8c03\u7528\u63a7\u4ef6\u6a21\u5757\nzone=name               #\u6307\u5b9a\u7a7a\u95f4=\u7a7a\u95f4\u7684\u540d\u5b57\n[burst=number]          #\u5141\u8bb8\u591a\u8bf7\u6c42\u51e0\u6b21\n[nodelay | delay=number]; #\u5ef6\u65f6<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \n\nlimit_conn_zone $remote_addr zone=conn_zone:10m;\nlimit_req_zone $remote_addr zone=req_zone:10m rate=1r\/s;    #\u8bbe\u7f6e\u4e00\u4e2a\u50a8\u5b58ip\u5730\u5740\uff0c\u50a8\u5b58\u5927\u5c0f\u4e3a10m\uff0c\u7a7a\u95f4\u540d\u5b57req_zone\uff0c\u4e00\u79d2\u53ea\u80fd\u8bf7\u6c42\u4e00\u6b21\u7684\u7a7a\u95f4\u3002\nserver {\n    listen 80;\n    server_name www.autoindex.com;\n    charset utf8;\n    limit_conn conn_zone 1;\n    limit_req zone=req_zone;    #\u8c03\u7528\u7a7a\u95f4\u540d\u5b57\u662freq_zone\u7684\u7a7a\u95f4\n    #limit_req zone=req_zone burst=5 nodelay;           #\u8c03\u7528\u7a7a\u95f4\u540d\u5b57\u662freq_zone\u7684\u7a7a\u95f4\uff0c\u6700\u5927\u9650\u5ea6\u53ef\u4ee5\u540c\u65f6\u8bbf\u95ee\u4e94\u6b21\uff0c\u6ca1\u6709\u5ef6\u8fdf\n\n    location \/ {\n        root \/code\/autoindex;\n        index index.html;\n    }\n}<\/code><\/pre>\n<h4>3\uff09\u6d4b\u8bd5<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# ab -n 20000 -c 20 http:\/\/www.autoindex.com\/index.html \n        -n        #\u8bf7\u6c42\u7684\u6b21\u6570\n        -c        #\u4e00\u6b21\u8bf7\u6c42\u5e76\u53d1\u7684\u6b21\u6570<\/code><\/pre>\n<h2>\u4e8c\u3001nginx\u7684location\u914d\u7f6e<\/h2>\n<pre><code class=\"language-bash\">\u4f7f\u7528Nginx Location\u53ef\u4ee5\u63a7\u5236\u8bbf\u95ee\u7f51\u7ad9\u7684\u8def\u5f84,\u4f46\u4e00\u4e2aserver\u53ef\u4ee5\u6709\u591a\u4e2alocation\u914d\u7f6e, \u591a\u4e2alocation\u7684\u4f18\u5148\u7ea7\u8be5\u5982\u4f55\u533a\u5206<\/code><\/pre>\n<h3>1.\u8bed\u6cd5<\/h3>\n<pre><code class=\"language-bash\">Syntax: location [ = | ~ | ~* | ^~ ] uri { ... }\n        location @name { ... }\nDefault:    \u2014\nContext:    server, location<\/code><\/pre>\n<h3>2.location\u5339\u914d\u7b26<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u5339\u914d\u7b26<\/strong><\/th>\n<th><strong>\u5339\u914d\u89c4\u5219<\/strong><\/th>\n<th><strong>\u4f18\u5148\u7ea7<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>=<\/td>\n<td>\u7cbe\u786e\u5339\u914d<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>^~<\/td>\n<td>\u4ee5\u67d0\u4e2a\u5b57\u7b26\u4e32\u5f00\u5934<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>~<\/td>\n<td>\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>~*<\/td>\n<td>\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u6b63\u5219\u5339\u914d<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>\/<\/td>\n<td>\u901a\u7528\u5339\u914d\uff0c\u4efb\u4f55\u8bf7\u6c42\u90fd\u4f1a\u5339\u914d\u5230<\/td>\n<td>4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>3.\u4f18\u5148\u7ea7\u9a8c\u8bc1<\/h3>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/youxianji.conf\nserver {\n    listen 80;\n    server_name linux.test.com;\n    location \/ {\n        default_type text\/html;\n        return 200 &quot;location \/&quot;;\n    }\n\n    location =\/ {\n        default_type text\/html;\n        return 200 &quot;location =\/&quot;;\n    }\n\n    location ~ \/ {\n        default_type text\/html;\n        return 200 &quot;location ~\/&quot;;\n    }\n\n    # location ^~ \/ {\n    #   default_type text\/html;\n    #   return 200 &quot;location ^~&quot;;\n    # }\n}<\/code><\/pre>\n<h3>4.Locaiton\u5e94\u7528\u573a\u666f<\/h3>\n<pre><code class=\"language-bash\"># \u901a\u7528\u5339\u914d\uff0c\u4efb\u4f55\u8bf7\u6c42\u90fd\u4f1a\u5339\u914d\u5230\nlocation \/ {\n    ...\n}\n\n# \u4e25\u683c\u533a\u5206\u5927\u5c0f\u5199\uff0c\u5339\u914d\u4ee5.php\u7ed3\u5c3e\u7684\u90fd\u8d70\u8fd9\u4e2alocation    \nlocation ~ \\.php$ {\n    ...\n}\n\n# \u4e25\u683c\u533a\u5206\u5927\u5c0f\u5199\uff0c\u5339\u914d\u4ee5.jsp\u7ed3\u5c3e\u7684\u90fd\u8d70\u8fd9\u4e2alocation \nlocation ~ \\.jsp$ {\n    ...\n}\n\n# \u4e0d\u533a\u5206\u5927\u5c0f\u5199\u5339\u914d\uff0c\u53ea\u8981\u7528\u6237\u8bbf\u95ee.jpg,gif,png,js,css \u90fd\u8d70\u8fd9\u6761location\nlocation ~* .*\\.(jpg|gif|png|js|css)$ {\n    ...\n}\n\nhttp:\/\/linux.test.com\/1.PHP\nhttp:\/\/linux.test.com\/1.JPG\nhttp:\/\/linux.test.com\/1.jsp\nhttp:\/\/linux.test.com\/1.Gif\nhttp:\/\/linux.test.com\/1.PnG\nhttp:\/\/linux.test.com\/1.JsP<\/code><\/pre>\n<h2>\u4e09\u3001LNMP\u67b6\u6784<\/h2>\n<h3>1.\u7b80\u4ecb<\/h3>\n<pre><code class=\"language-bash\">LNMP\u662f\u4e00\u5957\u6280\u672f\u7684\u7ec4\u5408\uff0cL=Linux\u3001N=Nginx\u3001M~=MySQL\u3001P~=PHP\n\u4e0d\u4ec5\u4ec5\u53ea\u6709\u8fd9\u4e9b\u670d\u52a1\uff0c\u8fd8\u6709\u5f88\u591a\nredis\\elasticsearch\\kibana\\logstash\\zabbix\\git\\jenkins\\kafka\\hbase\\hadoop\\spark\\flink<\/code><\/pre>\n<h3>2.LNMP\u67b6\u6784\u5de5\u4f5c\u65b9\u5f0f<\/h3>\n<pre><code class=\"language-bash\">\u9996\u5148Nginx\u670d\u52a1\u662f\u4e0d\u80fd\u5904\u7406\u52a8\u6001\u8bf7\u6c42\uff0c\u90a3\u4e48\u5f53\u7528\u6237\u53d1\u8d77\u52a8\u6001\u8bf7\u6c42\u65f6, Nginx\u53c8\u662f\u5982\u4f55\u8fdb\u884c\u5904\u7406\u7684\u3002\n    1.\u9759\u6001\u8bf7\u6c42\uff1a\u8bf7\u6c42\u7684\u5185\u5bb9\u662f\u9759\u6001\u6587\u4ef6\u5c31\u662f\u9759\u6001\u8bf7\u6c42\n        1\uff09\u9759\u6001\u6587\u4ef6\uff1a\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668\uff0c\u6c38\u8fdc\u4e0d\u4f1a\u6539\u53d8\u7684\u6587\u4ef6\u5c31\u662f\u9759\u6001\u6587\u4ef6\n        2\uff09html\u5c31\u662f\u4e00\u4e2a\u6807\u51c6\u7684\u9759\u6001\u6587\u4ef6\n    2.\u52a8\u6001\u8bf7\u6c42\uff1a\u8bf7\u6c42\u7684\u5185\u5bb9\u662f\u52a8\u6001\u7684\u5c31\u662f\u52a8\u6001\u8bf7\u6c42\n        1\uff09\u4e0d\u662f\u771f\u5b9e\u5b58\u5728\u670d\u52a1\u5668\u4e0a\u7684\u5185\u5bb9\uff0c\u662f\u901a\u8fc7\u6570\u636e\u5e93\u6216\u8005\u5176\u4ed6\u670d\u52a1\u62fc\u51d1\u6210\u7684\u6570\u636e\n\n\u5f53\u7528\u6237\u53d1\u8d77http\u8bf7\u6c42\uff0c\u8bf7\u6c42\u4f1a\u88abNginx\u5904\u7406\uff0c\u5982\u679c\u662f\u9759\u6001\u8d44\u6e90\u8bf7\u6c42Nginx\u5219\u76f4\u63a5\u8fd4\u56de\uff0c\u5982\u679c\u662f\u52a8\u6001\u8bf7\u6c42Nginx\u5219\u901a\u8fc7fastcgi\u534f\u8bae\u8f6c\u4ea4\u7ed9\u540e\u7aef\u7684PHP\u7a0b\u5e8f\u5904\u7406\uff0c\u5177\u4f53\u5982\u4e0b\u56fe\u6240\u793a<\/code><\/pre>\n<h3>3.\u8bbf\u95ee\u6d41\u7a0b<\/h3>\n<pre><code class=\"language-bash\">1.\u6d4f\u89c8\u5668\u8f93\u5165\u57df\u540d\uff0c\u6d4f\u89c8\u5668\u4f1a\u62ff\u7740\u57df\u540d\u53d6DNS\u670d\u52a1\u5668\u89e3\u6790\n2.DNS\u670d\u52a1\u5668\u4f1a\u5c06\u57df\u540d\u89e3\u6790\u6210IP\n3.\u6d4f\u89c8\u5668\u4f1a\u53bb\u4e0eIP\u5bf9\u5e94\u670d\u52a1\u5668\u5efa\u7acbTCP\\IP\u8fde\u63a5\n4.\u8fde\u63a5\u5efa\u7acb\u5b8c\u6210\uff0c\u4f1a\u5411\u670d\u52a1\u5668\u53d1\u8d77\u8bf7\u6c42\uff0c\u8bf7\u6c42nginx\n5.nginx\u4f1a\u5224\u65ad\u8bf7\u6c42\u662f\u52a8\u6001\u7684\u8fd8\u662f\u9759\u6001\u7684\n    #\u9759\u6001\u8bf7\u6c42\n    location \\.jpg$ {\n        root \/code;\n    }\n    #\u52a8\u6001\u8bf7\u6c42\n    location \\.php$ {\n        fastcgi_pass 127.0.0.1:9000;\n        ... ...\n    }\n6.\u5982\u679c\u662f\u9759\u6001\u8bf7\u6c42\uff0cnginx\u53bbcode\u76ee\u5f55\u83b7\u53d6\uff0c\u76f4\u63a5\u8fd4\u56de\n7.\u5982\u679c\u662f\u52a8\u6001\u8bf7\u6c42\uff0cnginx\u4f1a\u901a\u8fc7fastcgi\u534f\u8bae\u8fde\u63a5PHP\u670d\u52a1\u7684php-fpm\u7ba1\u7406\u8fdb\u7a0b<\/code><\/pre>\n<pre><code class=\"language-bash\">8.php-fpm\u7ba1\u7406\u8fdb\u7a0b\u4f1a\u4e0b\u53d1\u5de5\u4f5c\u7ed9 wrapper\u5de5\u4f5c\u8fdb\u7a0b\n9.wrapper\u5de5\u4f5c\u8fdb\u7a0b\u5224\u65ad\u662f\u4e0d\u662f\u7b80\u5355\u7684php\u5185\u5bb9\n10.\u5982\u679c\u53ea\u662fphp\u5185\u5bb9\u5219\u4f7f\u7528php\u89e3\u6790\u5668\u89e3\u6790\u540e\u76f4\u63a5\u8fd4\u56de\n11.\u5982\u679c\u8fd8\u9700\u8981\u8bfb\u53d6\u6570\u636e\u5e93\uff0cwrapper\u5de5\u4f5c\u8fdb\u7a0b\u4f1a\u53bb\u6570\u636e\u5e93\u8bfb\u53d6\u6570\u636e\uff0c\u518d\u8fd4\u56de\u6570\u636e\n12.\u6570\u636e\u6d41\u8f6c\u8fc7\u7a0b\uff1a\n    1\uff09\u8bf7\u6c42\uff1a\u6d4f\u89c8\u5668 &gt; \u8d1f\u8f7d\u5747\u8861 &gt; nginx &gt; php-fpm &gt; wrapper &gt; mysql\n    2\uff09\u54cd\u5e94\uff1amysql &gt; wrapper &gt; php-fpm &gt; nginx &gt; \u8d1f\u8f7d\u5747\u8861 &gt; \u6d4f\u89c8\u5668<\/code><\/pre>\n<h2>\u56db\u3001LNMP\u67b6\u6784\u642d\u5efa<\/h2>\n<h3>1.\u642d\u5efanginx<\/h3>\n<h4>1\uff09\u914d\u7f6e\u5b98\u65b9\u6e90<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/yum.repos.d\/nginx.repo\n[nginx-stable]\nname=nginx stable repo\nbaseurl=http:\/\/nginx.org\/packages\/centos\/7\/$basearch\/\ngpgcheck=1\nenabled=1\ngpgkey=https:\/\/nginx.org\/keys\/nginx_signing.key\nmodule_hotfixes=true<\/code><\/pre>\n<h4>2\uff09\u5b89\u88c5nginx<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# yum install -y nginx<\/code><\/pre>\n<h4>3\uff09\u914d\u7f6enginx<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/nginx.conf \nuser  www;<\/code><\/pre>\n<h4>4\uff09\u521b\u5efa\u7528\u6237<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# groupadd www -g 666\n[root@web01 ~]# useradd www -u 666 -g 666 -s \/sbin\/nologin -M<\/code><\/pre>\n<h4>5\uff09\u542f\u52a8nginx<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# systemctl start nginx\n[root@web01 ~]# systemctl enable nginx\nCreated symlink from \/etc\/systemd\/system\/multi-user.target.wants\/nginx.service to \/usr\/lib\/systemd\/system\/nginx.service.\n\n#\u9a8c\u8bc1\u542f\u52a8\n[root@web01 ~]# ps -ef | grep nginx\nroot       9953      1  0 11:17 ?        00:00:00 nginx: master process \/usr\/sbin\/nginx -c \/etc\/nginx\/nginx.conf\nwww        9954   9953  0 11:17 ?        00:00:00 nginx: worker process<\/code><\/pre>\n<h3>2.\u5b89\u88c5PHP<\/h3>\n<h4>1\uff09\u5b89\u88c5\u65b9\u5f0f\u4e00<\/h4>\n<pre><code class=\"language-bash\"># rpm -Uvh https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\n# rpm -Uvh https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm\n\n[root@nginx ~]# yum remove php-mysql-5.4 php php-fpm php-common\n\n#\u914d\u7f6e\u7b2c\u4e09\u65b9\u6e90\n[root@nginx ~]# vim \/etc\/yum.repos.d\/php.repo\n[php-webtatic]\nname = PHP Repository\nbaseurl = http:\/\/us-east.repo.webtatic.com\/yum\/el7\/x86_64\/\ngpgcheck = 0\n\n[root@nginx ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb<\/code><\/pre>\n<h4>2\uff09\u5b89\u88c5\u65b9\u5f0f\u4e8c<\/h4>\n<pre><code class=\"language-bash\">1.\u4e0a\u4f20\u5305\n[root@web01 ~]# rz\n[root@web01 ~]# ll\n-rw-r--r--. 1 root root 19889622 Nov 22 15:52 p-hp.tar.gz\n\n2.\u89e3\u538b\u5305\n[root@web01 ~]# tar xf php.tar.gz\n\n3.\u672c\u5730\u5b89\u88c5php\u7684rpm\u5305\n[root@web01 ~]# yum localinstall -y *.rpm<\/code><\/pre>\n<h4>3\uff09\u914d\u7f6ephp<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/php-fpm.d\/www.conf \nuser = www\ngroup = www<\/code><\/pre>\n<h4>4\uff09\u542f\u52a8\u670d\u52a1<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# systemctl start php-fpm\n[root@web01 ~]# systemctl enable php-fpm\nCreated symlink from \/etc\/systemd\/system\/multi-user.target.wants\/php-fpm.service to \/usr\/lib\/systemd\/system\/php-fpm.service.<\/code><\/pre>\n<h4>5\uff09\u9a8c\u8bc1\u542f\u52a8<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# ps -ef | grep php-fpm\nroot      10195      1  0 11:29 ?        00:00:00 php-fpm: master process (\/etc\/php-fpm.conf)\nwww       10196  10195  0 11:29 ?        00:00:00 php-fpm: pool www\nwww       10197  10195  0 11:29 ?        00:00:00 php-fpm: pool www\nwww       10198  10195  0 11:29 ?        00:00:00 php-fpm: pool www\nwww       10199  10195  0 11:29 ?        00:00:00 php-fpm: pool www\nwww       10200  10195  0 11:29 ?        00:00:00 php-fpm: pool www<\/code><\/pre>\n<h3>3.\u642d\u5efa\u4ea4\u4f5c\u4e1a\u9875\u9762<\/h3>\n<h4>1\uff09\u914d\u7f6enginx<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/default.conf \nserver {\n    listen 80;\n    server_name linux.zuoye.com;\n\n    location \/ {\n        root \/code\/zuoye;\n        index index.html;\n    }\n}<\/code><\/pre>\n<h4>2\uff09\u521b\u5efa\u7ad9\u70b9\u76ee\u5f55<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# mkdir \/code\/zuoye -p<\/code><\/pre>\n<h4>3\uff09\u4e0a\u4f20\u4ee3\u7801<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# cd \/code\/zuoye\/\n[root@web01 zuoye]# rz\n[root@web01 zuoye]# ll\n-rw-r--r--. 1 root root 26995 Nov 22 16:47 kaoshi.zip\n[root@web01 zuoye]# unzip kaoshi.zip      \n[root@web01 zuoye]# ll\n-rw-r--r--. 1 root root 38772 Apr 27  2018 bg.jpg\n-rw-r--r--. 1 root root  2633 May  4  2018 index.html\n-rw-r--r--. 1 root root    52 May 10  2018 info.php\n-rw-r--r--. 1 root root  1192 Jan 10  2020 upload_file.php<\/code><\/pre>\n<h4>4\uff09\u4fee\u6539\u4ee3\u7801\u4e2d\u4e0a\u4f20\u4f5c\u4e1a\u4f4d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/code\/zuoye\/upload_file.php\n$wen=&quot;\/code\/zuoye\/upload&quot;;<\/code><\/pre>\n<h4>5\uff09\u6388\u6743<\/h4>\n<pre><code class=\"language-bash\">[root@web01 zuoye]# chown -R www.www \/code\/<\/code><\/pre>\n<h4>6\uff09\u91cd\u542f\u670d\u52a1<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# systemctl restart nginx<\/code><\/pre>\n<h4>7\uff09\u914d\u7f6ehosts\u8bbf\u95ee\u6d4b\u8bd5<\/h4>\n<pre><code class=\"language-bash\">#\u914d\u7f6ehosts\n10.0.0.7 linux.zuoye.com\n\n#\u8bbf\u95ee\nhttp:\/\/linux.zuoye.com\/\n\n#\u6d4b\u8bd5\n\u4e0a\u4f20\u4ee3\u7801\u51fa\u9519\uff0c\u62a5\u9519405\uff0c\u56e0\u4e3anginx\u6ca1\u529e\u6cd5\u5904\u7406php\u4ee3\u7801\u7a0b\u5e8f<\/code><\/pre>\n<h3>4.\u5173\u8054nginx\u4e0ephp<\/h3>\n<h4>1\uff09\u5173\u8054\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">#fastcgi_pass\uff0cnginx\u8fde\u63a5php\u7684\u4ee3\u7406\u534f\u8bae\nSyntax: fastcgi_pass address;\nDefault:    \u2014\nContext:    location, if in location\n\n#\u6307\u5b9a\u8bf7\u6c42\u7684\u6587\u4ef6\nSyntax: fastcgi_param parameter value [if_not_empty];\nDefault:    \u2014\nContext:    http, server, location\n\n#\u6307\u5b9a\u9ed8\u8ba4\u7684php\u9875\u9762\nSyntax: fastcgi_index name;\nDefault:    \u2014\nContext:    http, server, location<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/default.conf \nserver {\n    listen 80;\n    server_name linux.zuoye.com;\n\n    location \/ {\n        root \/code\/zuoye;\n        index index.html;\n    }\n\n    location ~* \\.php$ {\n        fastcgi_pass localhost:9000;\n        fastcgi_param SCRIPT_FILENAME \/code\/zuoye\/$fastcgi_script_name;\n        include fastcgi_params;\n    }\n}<\/code><\/pre>\n<h4>3\uff09\u8bbf\u95ee\u9875\u9762\u6d4b\u8bd5<\/h4>\n<pre><code class=\"language-bash\">1.\u8bbf\u95ee\u9875\u9762\nhttp:\/\/linux.zuoye.com\/\n\n2.\u4e0a\u4f20\u56fe\u7247\u6587\u4ef6\n\u6210\u529f\n\n3.\u4e0a\u4f20\u4e00\u4e2a\u5927\u6587\u4ef6\n\u5931\u8d25\uff0c413\u62a5\u9519\uff0c\u8bf4\u6587\u4ef6\u8fc7\u5927\n#\u89e3\u51b3\uff1a\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u914d\u7f6e\n    [root@web01 ~]# vim \/etc\/nginx\/nginx.conf\n    http {\n        ... ...\n        client_max_body_size 200m;\n        ... ...\n    }\n    [root@web01 ~]# systemctl restart nginx\n\n    [root@web01 ~]# vim \/etc\/php.ini\n    upload_max_filesize = 200M\n    post_max_size = 200M\n    [root@web01 ~]# systemctl restart php-fpm\n\n4.\u91cd\u65b0\u4e0a\u4f20\u6587\u4ef6\u6d4b\u8bd5\n\u6210\u529f<\/code><\/pre>\n<h3>5.\u642d\u5efamariadb<\/h3>\n<h4>1\uff09\u5b89\u88c5<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# yum install -y mariadb-server<\/code><\/pre>\n<h4>2\uff09\u542f\u52a8\u670d\u52a1<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# systemctl start mariadb\n[root@web01 ~]# systemctl enable mariadb\nCreated symlink from \/etc\/systemd\/system\/multi-user.target.wants\/mariadb.service to \/usr\/lib\/systemd\/system\/mariadb.service.<\/code><\/pre>\n<h4>3\uff09\u9a8c\u8bc1\u542f\u52a8<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# ps -ef | grep mariadb\nmysql     11006  10841  1 12:06 ?        00:00:00 \/usr\/libexec\/mysqld --basedir=\/usr --datadir=\/var\/lib\/mysql --plugin-dir=\/usr\/lib64\/mysql\/plugin --log-error=\/var\/log\/mariadb\/mariadb.log --pid-file=\/var\/run\/mariadb\/mariadb.pid --socket=\/var\/lib\/mysql\/mysql.sock<\/code><\/pre>\n<h4>4\uff09\u8fde\u63a5<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# mysql\nWelcome to the MariaDB monitor.  Commands end with ; or \\g.\nYour MariaDB connection id is 2\nServer version: 5.5.68-MariaDB MariaDB Server\n\nCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.\n\nType &#039;help;&#039; or &#039;\\h&#039; for help. Type &#039;\\c&#039; to clear the current input statement.\n\nMariaDB [(none)]&gt; show databases;            #\u67e5\u770b\u6570\u636e\u5e93\n+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| mysql              |\n| performance_schema |\n| test               |\n+--------------------+\n4 rows in set (0.00 sec)<\/code><\/pre>\n<h4>5\uff09\u8bbe\u7f6e\u6570\u636e\u5e93\u5bc6\u7801<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# mysqladmin -uroot password &#039;123&#039;\n\n#\u4f7f\u7528\u5bc6\u7801\u8fde\u63a5\u6570\u636e\u5e93\n[root@web01 ~]# mysql -uroot -p123\nWelcome to the MariaDB monitor.  Commands end with ; or \\g.\nYour MariaDB connection id is 5\nServer version: 5.5.68-MariaDB MariaDB Server\n\nCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.\n\nType &#039;help;&#039; or &#039;\\h&#039; for help. Type &#039;\\c&#039; to clear the current input statement.\n\nMariaDB [(none)]&gt;<\/code><\/pre>\n<h3>6.\u6d4b\u8bd5PHP\u548cmariadb\u5173\u8054<\/h3>\n<h4>1\uff09\u7f16\u5199php\u6d4b\u8bd5\u8fde\u63a5\u6570\u636e\u5e93\u7684\u4ee3\u7801<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/code\/zuoye\/test.php\n&lt;?php\n    $servername = &quot;localhost&quot;;\n    $username = &quot;root&quot;;\n    $password = &quot;123&quot;;\n\n    \/\/ \u521b\u5efa\u8fde\u63a5\n    $conn = mysqli_connect($servername, $username, $password);\n\n    \/\/ \u68c0\u6d4b\u8fde\u63a5\n    if (!$conn) {\n        die(&quot;Connection failed: &quot; . mysqli_connect_error());\n    }\n    echo &quot;\u5c0f\u54e5\u54e5,php\u53ef\u4ee5\u8fde\u63a5MySQL...&quot;;\n?&gt;\n\n&lt;img style=&#039;width:100%;height:100%;&#039; src=https:\/\/blog.drig&gt;<\/code><\/pre>\n<h4>2\uff09\u8bbf\u95ee\u6d4b\u8bd5<\/h4>\n<pre><code class=\"language-bash\">http:\/\/linux.zuoye.com\/test.php<\/code><\/pre>\n<h2>\u4e94\u3001\u642d\u5efawordpress\u535a\u5ba2<\/h2>\n<h3>1.\u4e0a\u4f20\u4ee3\u7801<\/h3>\n<pre><code class=\"language-bash\">[root@web01 code]# rz\n[root@web01 code]# ll\n-rw-r--r--. 1 root root 11098483 Sep 12 17:52 wordpress-5.0.3-zh_CN.tar.gz<\/code><\/pre>\n<h3>2.\u89e3\u538b\u4ee3\u7801<\/h3>\n<pre><code class=\"language-bash\">[root@web01 code]# tar xf wordpress-5.0.3-zh_CN.tar.gz<\/code><\/pre>\n<h3>3.\u6388\u6743<\/h3>\n<pre><code class=\"language-bash\">[root@web01 code]# chown -R www.www wordpress<\/code><\/pre>\n<h3>4.\u914d\u7f6enginx<\/h3>\n<pre><code class=\"language-bash\">[root@web01 code]# vim \/etc\/nginx\/conf.d\/linux.wp.com.conf\nserver {\n    listen 80;\n    server_name linux.wp.com;\n\n    location \/ {\n        root \/code\/wordpress;\n        index index.php; \n    }\n\n    location ~* \\.php$ {\n        fastcgi_pass 127.0.0.1:9000;\n        fastcgi_param SCRIPT_FILENAME \/code\/wordpress\/$fastcgi_script_name;\n        include fastcgi_params;\n    }\n}<\/code><\/pre>\n<h3>5.\u91cd\u542f\u8bbf\u95ee<\/h3>\n<pre><code class=\"language-bash\">#\u68c0\u67e5\u914d\u7f6e\n[root@web01 code]# nginx -t\nnginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful\n\n#\u91cd\u542f\n[root@web01 code]# systemctl restart nginx<\/code><\/pre>\n<h3>6.\u8bbf\u95ee\u6d4b\u8bd5<\/h3>\n<pre><code class=\"language-bash\">#\u914d\u7f6ehosts\n10.0.0.7 linux.wp.com\n\n#\u8bbf\u95ee\nhttp:\/\/linux.wp.com\/<\/code><\/pre>\n<h3>7.\u521b\u5efa\u6570\u636e\u5e93<\/h3>\n<pre><code class=\"language-bash\">[root@web01 code]# mysql -uroot -p123\n\nMariaDB [(none)]&gt; create database wordpress;\nQuery OK, 1 row affected (0.00 sec)\n\nMariaDB [(none)]&gt; show databases;\n+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| mysql              |\n| performance_schema |\n| test               |\n| wordpress          |\n+--------------------+\n5 rows in set (0.00 sec)<\/code><\/pre>\n<h3>8.\u6839\u636e\u9875\u9762\u63d0\u793a\u64cd\u4f5c<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001nginx\u6a21\u5757 1.\u76ee\u5f55\u7d22\u5f15\u6a21\u5757 [root@web01 ~]# vim \/etc\/nginx\/conf. [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":254,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[21,19,58,22,57,20],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/323"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=323"}],"version-history":[{"count":1,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/323\/revisions"}],"predecessor-version":[{"id":8762,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/323\/revisions\/8762"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/254"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}