{"id":2493,"date":"2020-10-25T15:52:23","date_gmt":"2020-10-25T07:52:23","guid":{"rendered":"https:\/\/www.charflower.com\/?p=2493"},"modified":"2020-10-25T15:58:48","modified_gmt":"2020-10-25T07:58:48","slug":"nginx-%e9%9b%86%e7%be%a4%e6%9e%b6%e6%9e%84-1-lanmp%e9%83%a8%e7%bd%b2","status":"publish","type":"post","link":"https:\/\/www.charflower.com\/?p=2493","title":{"rendered":"Nginx-\u96c6\u7fa4\u67b6\u6784-1-LANMP\u90e8\u7f72"},"content":{"rendered":"\n<p><strong>\u5b9e\u6218\u5185\u5bb9\uff1a<\/strong><\/p>\n\n\n\n<p><strong>    \u4f7f\u7528\u4e09\u53f0Linux\u670d\u52a1\u5668\uff0c\u4e00\u53f0\u8bbe\u5907\u5b89\u88c5Nginx\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\uff0c\u4e24\u53f0\u8bbe\u5907\u90e8\u7f72LAP\uff08\u53d1\u5e03\u4e24\u4e2a\u7f51\u7ad9wordpress\u3001discuz\uff09+ \u4e24\u53f0Mysql\uff08\u4e3b\u4ece\u540c\u6b65\u3001\u53ef\u4ee5\u516c\u7528\uff09<\/strong><\/p>\n\n\n\n<p><strong>\u5728\u6b64\u96c6\u7fa4\u67b6\u6784\u90e8\u7f72\u4e2d\uff0c\u914d\u7f6e\u4e0d\u518d\u8fc7\u4e8e\u8be6\u7ec6\u63cf\u8ff0\uff0c\u6709\u7ec6\u8282\u95ee\u9898\u53ef\u4ee5\u7ffb\u9605\u4e4b\u524d\u7684LAMP\u6e90\u7801\u90e8\u7f72\u7b14\u8bb0\uff1b<\/strong><\/p>\n\n\n\n<h4><strong>1\u3001\u62d3\u6251\uff1a<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"593\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/1-1-1024x593.png\" alt=\"\" class=\"wp-image-2495\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/1-1-1024x593.png 1024w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/1-1-300x174.png 300w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/1-1-768x444.png 768w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/1-1.png 1303w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption> <strong>\u76ee\u7684\uff1a\u5728\u4e24\u53f0Web\u670d\u52a1\u5668\u4e0a\u90fd\u90e8\u7f72Wordpress\u548cdiscuz\uff1b\u7136\u540e\u4f7f\u7528Nginx\u670d\u52a1\u5668\u8fdb\u884c\u53cd\u5411\u4ee3\u7406\uff1b\u5f53\u7528\u6237\u8bbf\u95eebbs.zhanggeng.com\u7684\u65f6\u5019\uff0c\u8ba9\u5176\u5728\u4e24\u4e2adiscuz\u4e4b\u95f4\u8fdb\u884c 1\uff1a1\u8f6e\u8be2\u8bbf\u95ee\uff1b\u5f53\u7528\u6237\u8bbf\u95eeblog.zhanggeng.com\u7684\u65f6\u5019\uff0c\u8ba9\u5176\u5728\u4e24\u4e2awordpress\u4e4b\u95f4\u8fdb\u884c 1\uff1a1\u8f6e\u8be2\u8bbf\u95ee\uff1b\u6240\u4ee5\u9700\u8981\u5728web\u670d\u52a1\u5668\u4e0a\u505a\u865a\u62df\u4e3b\u673a\uff1b\u5e76\u4e14Nginx\u4e0a\u4e5f\u9700\u8981\u505a\u865a\u62df\u4e3b\u673a\uff1b<\/strong> <\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-vivid-cyan-blue-background-color has-vivid-cyan-blue-color is-style-wide\" \/>\n\n\n\n<h4><strong>2\u3001\u90e8\u7f72LAMP\u3001Mysql\u4e3b\u4ece\u540c\u6b65\u3001\u6388\u6743wordpress\uff0cdiscuz\uff1b<\/strong><\/h4>\n\n\n\n<p><strong>\u90e8\u7f72\u5728\u4e24\u53f0\u8bbe\u5907\u4e0a\uff1a<\/strong><\/p>\n\n\n\n<p><strong>Lamp1\uff1a192.168.169.202<\/strong>    <strong>Lamp2\uff1a192.168.169.203<\/strong><\/p>\n\n\n\n<p><strong>1\uff09\u3001\u5b89\u88c5\u5404\u79cd\u8f6f\u4ef6\u5305\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# yum install -y httpd mariadb mariadb-server php php-mysql php-devel mysql-devel<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp2 ~]# yum install -y httpd mariadb mariadb-server php php-mysql php-devel mysql-devel<\/code><\/pre>\n\n\n\n<p><strong>yum\u5b89\u88c5\u7684Apache\uff0c\u9ed8\u8ba4\u5728conf.d\u76ee\u5f55\u4e0b\u5b58\u5728php.conf,\u6240\u4ee5\u9ed8\u8ba4LAMP\u5c31\u5173\u8054\u8d77\u6765\u4e86\uff1b<\/strong><\/p>\n\n\n\n<p><strong>2\uff09\u3001\u914d\u7f6eMysql\u4e3b\u4ece\u540c\u6b65\uff1aLamp1\u4f5c\u4e3aMaster   Lamp2\u4f5c\u4e3aSlave<\/strong><\/p>\n\n\n\n<p><strong>A:   Lamp1\u4e0a\u505a\u5982\u4e0b\u914d\u7f6e\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5728\/etc\/my.cnf\u4e2d\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff1a\nlog-bin=mysql-binlog-master\nserver-id=1\n\nsystemctl start mariadb\n\n\n[root@Lamp1 ~]# mysql\nMariaDB [(none)]&gt; grant replication slave on *.* to 'slave'@'192.168.169.203' identified by '123456'\uff1b\nMariaDB [(none)]&gt; create database wordpress;\nMariaDB [(none)]&gt; create database discuz;\nMariaDB [mysql]&gt; grant all on wordpress.* to 'wordpress'@'%' identified by 'wordpress';\nMariaDB [mysql]&gt; grant all on discuz.* to 'discuz'@'%' identified by 'discuz';<\/code><\/pre>\n\n\n\n<p><strong>\u67e5\u770bposition\u548c\u4e8c\u8fdb\u5236\u6587\u4ef6\u540d\uff0c\u5e76\u4f5c\u8bb0\u5f55\uff1a<\/strong><\/p>\n\n\n\n<p><strong>mysql-binlog-master.000003      871<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"747\" height=\"190\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/2.png\" alt=\"\" class=\"wp-image-2496\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/2.png 747w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/2-300x76.png 300w\" sizes=\"(max-width: 747px) 100vw, 747px\" \/><\/figure>\n\n\n\n<p><strong>B:  Lamp2\u4e0a\u505a\u5982\u4e0b\u914d\u7f6e\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5728\/etc\/my.cnf\u4e2d\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\nserver-id=3\n\nsystemctl start mariadb\n\nMariaDB [(none)]&gt; change master to\n    -&gt; master_host='192.168.169.202',\n    -&gt; master_user='slave',\n    -&gt; master_password='123456',\n    -&gt; master_log_file='mysql-binlog-master.000003',     #\u4e0eMaster\u4e0a\u4e00\u81f4\n    -&gt; master_log_pos=871;                                               #\u4e0eMaster\u4e0a\u4e00\u81f4\n\nMariaDB [(none)]&gt; start slave;\n\nMariaDB [(none)]&gt; show slave status\\G     #\u67e5\u770b\u540c\u6b65\u72b6\u6001<\/code><\/pre>\n\n\n\n<p><strong>C\uff1aLamp1\u4e0a\u505a\u5982\u4e0b\u914d\u7f6e\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# mysqldump -A --events &gt; backup.sql\n[root@Lamp1 ~]# scp backup.sql root@192.168.169.203:\/etc\/<\/code><\/pre>\n\n\n\n<p><strong>D\uff1aLamp2\u4e0a\u505a\u5982\u4e0b\u914d\u7f6e\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MariaDB [(none)]&gt; stop slave;     #\u5148\u505c\u6b62\u540c\u6b65\n\n[root@Lamp2 ~]# mysql &lt; \/etc\/backup.sql     #\u5bfc\u5165\u6570\u636e\u5e93\n\nMariaDB [(none)]&gt; start slave;       #\u5f00\u542f\u540c\u6b65\n\nMariaDB [(none)]&gt; select user from mysql.user;     #\u4f7f\u7528\u8be5\u547d\u4ee4\u67e5\u770b\u4e4b\u524d\u5728Master\u4e0a\u521b\u5efa\u7684\u7528\u6237\u5c31\u6709\u4e86\uff1b<\/code><\/pre>\n\n\n\n<p><strong>\u9700\u8981C\u548cD\u7684\u8fc7\u7a0b\u662f\u56e0\u4e3a\u4e24\u4e2a\u6570\u636e\u5e93\u5728\u5f00\u542f\u540c\u6b65\u4e4b\u524d\u7684\u6570\u636e\u662f\u4e0d\u4f1a\u88ab\u540c\u6b65\u7684\uff1b\u5982\u679c\u5148\u5f00\u542f\u540c\u6b65\uff0c\u7136\u540e\u518d\u521b\u5efawordpress\u3001discuz\u7528\u6237\u5c31\u4e0d\u9700\u8981C\u548cD\u7684\u5bfc\u5165\u6570\u636e\u5e93\u7684\u64cd\u4f5c\uff1b<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-vivid-cyan-blue-background-color has-vivid-cyan-blue-color is-style-wide\" \/>\n\n\n\n<h4><strong>3\u3001\u914d\u7f6eLamp1\u4e0a\u7684Apache\u865a\u62df\u4e3b\u673a\uff0c\u7136\u540e\u540c\u6b65\u7ed9Lamp2\uff1b<\/strong><\/h4>\n\n\n\n<p><strong>1\uff09\u3001\u914d\u7f6eLamp1\u5185\u5bb9\u5982\u4e0b<\/strong><\/p>\n\n\n\n<p><strong>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# vim \/etc\/httpd\/conf\/httpd.conf \nInclude \/usr\/local\/domain\n\u4fee\u6539#ServerName www.example.com:80   \u4e3a ServerName 127.0.0.1:80<\/code><\/pre>\n\n\n\n<p><strong>\u521b\u5efadomain\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# mkdir -p \/usr\/local\/domain<\/code><\/pre>\n\n\n\n<p><strong>\u521b\u5efa\u865a\u62df\u4e3b\u673a\u6587\u4ef6<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# cd \/usr\/local\/domain\/\n[root@Lamp1 domain]# touch bbs.zhanggeng.com\n[root@Lamp1 domain]# touch blog.zhanggeng.com<\/code><\/pre>\n\n\n\n<p><strong>\u57fa\u4e8e\u57df\u540d\u7684\u865a\u62df\u4e3b\u673a\u5185\u5bb9\u5982\u4e0b\uff1a<\/strong><\/p>\n\n\n\n<p><strong>bbs.zhanggeng.com\u5185\u5bb9\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost  *:80&gt;\n    ServerAdmin 1216653470@qq.com\n    DocumentRoot \"\/var\/www\/html\/discuz\"\n    ServerName bbs.zhanggeng.com\n    ErrorLog \"logs\/bbs-error_log\"\n    CustomLog \"logs\/bbs-access_log\" common\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p><strong>blog.zhanggeng.com\u5185\u5bb9\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost  *:80&gt;\n    ServerAdmin 1216653470@qq.com\n    DocumentRoot \"\/var\/www\/html\/wordpress\"\n    ServerName blog.zhanggeng.com\n    ErrorLog \"logs\/blog-error_log\"\n    CustomLog \"logs\/blog-access_log\" common\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p><strong>\u5728\/var\/www\/html\/\u4e0b\u521b\u5efawordpress\u4ee5\u53cadiscuz\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 domain]# mkdir -p \/var\/www\/html\/{discuz,wordpress}<\/code><\/pre>\n\n\n\n<p><strong>\u68c0\u6d4bApache\u8bed\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# httpd -t\nSyntax OK<\/code><\/pre>\n\n\n\n<p><strong>\u4e0a\u4f20Discuz\u548cWordpress\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"766\" height=\"159\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/3.png\" alt=\"\" class=\"wp-image-2497\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/3.png 766w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/3-300x62.png 300w\" sizes=\"(max-width: 766px) 100vw, 766px\" \/><\/figure>\n\n\n\n<p><strong>yum install -y unzip    #\u5b89\u88c5\u89e3\u538b\u5de5\u5177<\/strong><\/p>\n\n\n\n<p><strong>\u89e3\u538b\uff0c\u5e76\u5c06upload\u76ee\u5f55\u4e2d\u7684\u4e1c\u897f\u90fd\u653e\u5230discuz\u76ee\u5f55\u4e0b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# unzip Discuz_X3.2_SC_GBK.zip -d \/var\/www\/html\/discuz\/\n[root@Lamp1 ~]# cd \/var\/www\/html\/discuz\/\n[root@Lamp1 discuz]# cp -a upload\/* .<\/code><\/pre>\n\n\n\n<p><strong>\u89e3\u538b\uff0c\u5e76\u5c06\u89e3\u538b\u51fa\u7684\u5185\u5bb9\u90fd\u653e\u5230\u521b\u5efa\u7684wordpress\u76ee\u5f55\u4e0b\uff0c\u5c06\u89e3\u538b\u51fa\u7684\u76ee\u5f55\u5220\u9664\u6389\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# unzip wordpress-4.8.zip -d \/var\/www\/html\/wordpress\/\n[root@Lamp1 ~]# cd \/var\/www\/html\/wordpress\/\n[root@Lamp1 wordpress]# cp -a wordpress\/* .\n[root@Lamp1 wordpress]# rm -rf wordpress\/<\/code><\/pre>\n\n\n\n<p><strong>\u4fee\u6539\u5c5e\u4e3b\u5c5e\u7ec4\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# chown -R apache.apache \/var\/www\/html\/<\/code><\/pre>\n\n\n\n<p><strong>\u7531\u4e8e\u662f\u7528\u57fa\u4e8e\u57df\u540d\u505a\u7684\u865a\u62df\u4e3b\u673a\uff0c\u6240\u4ee5\u8bbf\u95ee\u7684\u65f6\u5019\u4e0d\u80fd\u4f7f\u7528IP\u5730\u5740\uff0c\u9700\u8981\u4f7f\u7528\u57df\u540d\uff1a<\/strong><\/p>\n\n\n\n<p><strong>\u4fee\u6539\u672c\u5730hosts\uff0c\u6dfb\u52a0\u5185\u5bb9\uff1a<\/strong><\/p>\n\n\n\n<p><strong>192.168.169.202 bbs.zhanggeng.com blog.zhanggeng.com<\/strong><\/p>\n\n\n\n<p><strong>systemctl restart httpd <\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u8bbf\u95ee\u57df\u540d\uff1a\u7531\u4e8e\u8fd8\u6ca1\u6709\u8fdb\u884c\u5b89\u88c5\uff0c\u6240\u4ee5\u8bbf\u95ee\u65f6302\u91cd\u5b9a\u5411\u5b89\u88c5\u8def\u5f84\uff0c\u5c5e\u4e8e\u6b63\u5e38\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"756\" height=\"341\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/4.png\" alt=\"\" class=\"wp-image-2498\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/4.png 756w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/4-300x135.png 300w\" sizes=\"(max-width: 756px) 100vw, 756px\" \/><\/figure>\n\n\n\n<p><strong>\u5728\u81ea\u5df1\u7535\u8111\u672c\u5730\u4fee\u6539host\u6587\u4ef6\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>192.168.169.202 bbs.zhanggeng.com\n192.168.169.202 blog.zhanggeng.com<\/code><\/pre>\n\n\n\n<p><strong>\u7531\u4e8e\u662f\u57fa\u4e8e\u57df\u540d\u7684\u865a\u62df\u4e3b\u673a\uff0c\u5f97\u7528\u57df\u540d\u8bbf\u95ee\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"850\" height=\"280\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/5.png\" alt=\"\" class=\"wp-image-2499\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/5.png 850w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/5-300x99.png 300w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/5-768x253.png 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1006\" height=\"410\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/6.png\" alt=\"\" class=\"wp-image-2500\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/6.png 1006w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/6-300x122.png 300w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/6-768x313.png 768w\" sizes=\"(max-width: 1006px) 100vw, 1006px\" \/><\/figure>\n\n\n\n<p><strong>2\uff09\u3001\u5c06Lamp1 \u7684Apache\u5185\u5bb9\u540c\u6b65\u7ed9 Lamp2<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># -r \u8868\u793a\u9012\u5f52\n[root@Lamp1 ~]# scp -r \/var\/www\/html\/  root@192.168.169.203:\/var\/www\/html\/\n\n[root@Lamp1 ~]# scp -r \/usr\/local\/domain\/ root@192.168.169.203:\/usr\/local\/domain\/\n\n[root@Lamp1 ~]# scp \/etc\/httpd\/conf\/httpd.conf root@192.168.169.203:\/etc\/httpd\/conf\/<\/code><\/pre>\n\n\n\n<p><strong>\u5728Lamp2\u4e0ahosts\u6dfb\u52a0\u89e3\u6790\uff0c\u5e76\u4fee\u6539\u5c5e\u4e3b\u5c5e\u7ec4\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp2 ~]# vim \/etc\/hosts\n192.168.169.203 bbs.zhanggeng.com blog.zhanggeng.com\n[root@Lamp2 ~]# chown -R apache.apache \/var\/www\/html\/<\/code><\/pre>\n\n\n\n<p><strong>\u4e24\u4e2a\u57df\u540d\u80fd\u591f\u6b63\u5e38\u8bbf\u95ee\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"710\" height=\"333\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/7.png\" alt=\"\" class=\"wp-image-2501\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/7.png 710w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/7-300x141.png 300w\" sizes=\"(max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-vivid-cyan-blue-background-color has-vivid-cyan-blue-color is-style-wide\" \/>\n\n\n\n<h4><strong>4\u3001Nginx\u8d1f\u8f7d\u5747\u8861+\u865a\u62df\u4e3b\u673a\u5185\u5bb9<\/strong><\/h4>\n\n\n\n<p><strong>LB\uff1a192.168.169.201    \u8be5\u4e3b\u673a\u4e0a\u5df2\u7ecf\u90e8\u7f72\u4e86Nginx\uff0c\u90e8\u7f72\u8fc7\u7a0b\u5728\u524d\u4e00\u7bc7\u6587\u7ae0\u4e2d\u63cf\u8ff0\u8fc7\u4e86\uff1b\u53ef\u4ee5\u53c2\u8003Nginx\u5165\u95e8\u4e0e\u5b89\u88c5\uff0c\u5c06\u5176\u642d\u5efa\u51fa\u6765\uff1b<\/strong><\/p>\n\n\n\n<p><strong>\u5728Nginx\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u5982\u4e0b\u6807\u7ea2\u90e8\u5206Nginx\u865a\u62df\u4e3b\u673a\u914d\u7f6e\uff1a<\/strong><\/p>\n\n\n\n<p><strong>\u914d\u7f6e\u6587\u4ef6\u8def\u5f84\uff1a\/usr\/local\/nginx\/conf\/nginx.conf<\/strong><\/p>\n\n\n\n<p><strong>\u5c06\u6807\u7ea2\u90e8\u5206\u5220\u9664\uff0c\u505ainclude\u8c03\u7528\uff1b<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"615\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/8-1024x615.png\" alt=\"\" class=\"wp-image-2503\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/8-1024x615.png 1024w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/8-300x180.png 300w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/8-768x461.png 768w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/8.png 1156w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>\u6807\u7ea2\u5185\u5bb9\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  server {\n        listen       80;\n        server_name  localhost;\n        location \/ {\n            root   html;\n            index  index.html index.htm;\n        }\n        error_page   500 502 503 504  \/50x.html;\n        location = \/50x.html {\n            root   html;\n        }\n    }<\/code><\/pre>\n\n\n\n<p><strong>\u4fee\u6539\u4e3a\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"747\" height=\"271\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/9.png\" alt=\"\" class=\"wp-image-2504\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/9.png 747w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/9-300x109.png 300w\" sizes=\"(max-width: 747px) 100vw, 747px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@LB ~]# mkdir -p \/usr\/local\/domain\n[root@LB ~]# \/usr\/local\/nginx\/sbin\/nginx -t\nnginx: the configuration file \/usr\/local\/nginx\/conf\/nginx.conf syntax is ok\nnginx: configuration file \/usr\/local\/nginx\/conf\/nginx.conf test is successful\n[root@LB ~]# \n\n[root@LB ~]# cd \/usr\/local\/domain\/\n[root@LB domain]# touch bbs.zhanggeng.com\n[root@LB domain]# touch blog.zhanggeng.com<\/code><\/pre>\n\n\n\n<p><strong>Nginx\u57fa\u4e8e\u57df\u540d\u7684\u865a\u62df\u4e3b\u673a\u5185\u5bb9\u5982\u4e0b\uff1a<\/strong><\/p>\n\n\n\n<p><strong>bbs.zhanggeng.com\u5185\u5bb9\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nupstream web_discuz {                                 #\u7c7b\u4f3c\u4e8eService-group\n          server 192.168.169.202:80;\n          server 192.168.169.203:80;\n}\nserver {\n        listen       80;\n        server_name  bbs.zhanggeng.com;      #\u5b9a\u4e49\u8bbf\u95ee\u7684\u57df\u540dbbs\n        location \/ {\n            root   html;\n            index  index.html index.htm;\n            proxy_set_header Host $host;             \n            proxy_pass http:\/\/web_discuz;        #\u542f\u52a8\u4ee3\u7406\uff0c\u5f53\u6709\u4eba\u8bbf\u95eebbs\u8c03\u7528web_discuz\u5185\u5bb9\n\n        }\n        error_page   500 502 503 504  \/50x.html;\n        location = \/50x.html {\n            root   html;\n        }\n    }<\/code><\/pre>\n\n\n\n<p><strong>\u6ce8\u91ca\uff1a\u7528\u6237\u4f7f\u7528\u57df\u540d\u8bbf\u95eeNginx\uff0c\u7136\u540eNginx\u901a\u8fc7\u5224\u65ad\u57df\u540d\u5c06\u8bf7\u6c42\u8df3\u8f6c\u5230\u540e\u7aefWeb\u670d\u52a1\u5668\u7684IP\u5730\u5740\u4e0a\uff0c\u5230Web\u670d\u52a1\u5668\u4e0a\u4e4b\u540e\uff0c\u7531\u4e8e\u662fIP\u5730\u5740\u8bbf\u95ee\u7684\uff0c\u6240\u4ee5Web\u670d\u52a1\u5668\u6ca1\u529e\u6cd5\u8fa8\u522b\u662f\u8bbf\u95eewordpress\u8fd8\u662fdiscuz\u7684\uff0c\u56e0\u6b64\u9700\u8981 proxy_set_header Host $host \u53c2\u6570\uff0c\u5c06\u57df\u540d\u4e5f\u4f20\u9012\u7ed9\u540e\u7aefWeb\u670d\u52a1\u5668\uff1b\u5728upstream\u53c2\u6570\u91cc\u9762\uff0c\u7528\u6237\u8bbf\u95ee\u7684\u65f6\u5019\uff0c\u4f1a\u5728\u4e24\u4e2a\u5730\u5740\u4e4b\u95f4\u8fdb\u884c1\uff1a1\u8f6e\u8be2\uff1b<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>blog.zhanggeng.com\u5185\u5bb9\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>upstream web_wordpress {   \n          server 192.168.169.202:80;\n          server 192.168.169.203:80;\n}\nserver {\n        listen       80;\n        server_name  blog.zhanggeng.com;     \n        location \/ {\n            root   html;\n            index  index.html index.htm;\n            proxy_set_header Host $host;          \n            proxy_pass http:\/\/web_wordpress;     \n\n        }\n        error_page   500 502 503 504  \/50x.html;\n        location = \/50x.html {\n            root   html;\n        }\n    }<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@LB domain]# \/usr\/local\/nginx\/sbin\/nginx -t\nnginx: the configuration file \/usr\/local\/nginx\/conf\/nginx.conf syntax is ok\nnginx: configuration file \/usr\/local\/nginx\/conf\/nginx.conf test is successful\n[root@LB domain]# \/usr\/local\/nginx\/sbin\/nginx -s reload<\/code><\/pre>\n\n\n\n<p><strong>\u4fee\u6539\u672c\u5730windows\u7684host\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>192.168.169.201 bbs.zhanggeng.com\n192.168.169.201 blog.zhanggeng.com<\/code><\/pre>\n\n\n\n<p><strong>\u672c\u5730\u8bbf\u95ee\u6d4b\u8bd5\uff1a\u4fee\u6539host\u4e4b\u540e\u8bbf\u95eeNginx\u6210\u529f\u8df3\u8f6c\uff1a\u5982\u4e0b<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"416\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/10-1024x416.png\" alt=\"\" class=\"wp-image-2505\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/10-1024x416.png 1024w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/10-300x122.png 300w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/10-768x312.png 768w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/10.png 1162w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"421\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/11-1024x421.png\" alt=\"\" class=\"wp-image-2506\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/11-1024x421.png 1024w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/11-300x123.png 300w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/11-768x316.png 768w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/11.png 1051w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>\u81f3\u6b64\uff0c\u8be5\u96c6\u7fa4\u67b6\u6784\u57fa\u672c\u5b8c\u6210\u3002<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-vivid-cyan-blue-background-color has-vivid-cyan-blue-color is-style-wide\" \/>\n\n\n\n<h2><strong>5\u3001\u914d\u7f6eApache Web\u670d\u52a1\u5668\u4e24\u8fb9\u4f7f\u7528inotifywait\u540c\u6b65<\/strong>\uff08\u9009\u505a\u90e8\u5206\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# yum install -y rsync\n[root@Lamp2 ~]# yum install -y rsync\n\n[root@Lamp1 ~]# ssh-keygen\n[root@Lamp1 ~]# ssh-copy-id 192.168.169.203\n\n\n[root@Lamp2 ~]# ssh-keygen\n[root@Lamp2 ~]# ssh-copy-id 192.168.169.202\n\n[root@Lamp1 ~]# yum install -y gcc gcc-c++\n[root@Lamp2 ~]# yum install -y gcc gcc-c++<\/code><\/pre>\n\n\n\n<p><strong>rz\u4e0a\u4f20inotify\uff0c\u5e76\u89e3\u538b\u3001\u7f16\u8bd1\u5b89\u88c5\uff1a<\/strong><\/p>\n\n\n\n<p><strong>Lamp1 \u548c Lamp2 \u90fd\u9700\u8981\u64cd\u4f5c\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# tar xf inotify-tools-3.13.tar.gz \n[root@Lamp1 ~]# cd inotify-tools-3.13\n[root@Lamp1 inotify-tools-3.13]# .\/configure \n\n[root@Lamp2 ~]# tar xf inotify-tools-3.13.tar.gz \n[root@Lamp2 ~]# cd inotify-tools-3.13\n[root@Lamp2 inotify-tools-3.13]# .\/configure <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"682\" height=\"199\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/12.png\" alt=\"\" class=\"wp-image-2507\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/12.png 682w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/12-300x88.png 300w\" sizes=\"(max-width: 682px) 100vw, 682px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"686\" height=\"140\" src=\"http:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/13.png\" alt=\"\" class=\"wp-image-2508\" srcset=\"https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/13.png 686w, https:\/\/www.charflower.com\/wp-content\/uploads\/2020\/10\/13-300x61.png 300w\" sizes=\"(max-width: 686px) 100vw, 686px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 inotify-tools-3.13]# make &amp;&amp; make install\n[root@Lamp2 inotify-tools-3.13]# make &amp;&amp; make install<\/code><\/pre>\n\n\n\n<p><strong>\u5728Lamp1 \u548c Lamp2 \u7f16\u5199\u811a\u672c\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# vim rsync.sh   \n\ninotifywait -mrq -e create,move,modify,delete,attrib \/var\/www\/html\/ | while read a b c \ndo\n\n   rsync -azP \/var\/www\/html\/ root@192.168.169.203:\/var\/www\/html\/\n\ndone\n\n[root@Lamp1 ~]# scp rsync.sh 192.168.169.203:\/root\/\n\n[root@Lamp2 ~]# vim rsync.sh   \n\ninotifywait -mrq -e create,move,modify,delete,attrib \/var\/www\/html\/ | while read a b c \ndo\n\n   rsync -azP \/var\/www\/html\/ root@192.168.169.202:\/var\/www\/html\/\n\ndone<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@Lamp1 ~]# chmod +x rsync.sh \n[root@Lamp2 ~]# chmod +x rsync.sh \n\n[root@Lamp1 ~]# .\/rsync.sh &amp;       #\u540e\u53f0\u8fd0\u884c\u8be5\u811a\u672c\n[root@Lamp2 ~]# .\/rsync.sh &amp;       #\u540e\u53f0\u8fd0\u884c\u8be5\u811a\u672c<\/code><\/pre>\n\n\n\n<p><strong>\u505a\u5230\u8fd9\u91cc\u9700\u8981\u4fdd\u5b58\u5feb\u7167\u65b9\u4fbf\u540e\u9762\u7684\u5b9e\u9a8c\uff0c\u5feb\u7167\u540d\u79f0\uff1aLAMP+Nginx\u96c6\u7fa4\u67b6\u6784-1<\/strong><\/p>\n\n\n\n<p><strong>\u540e\u9762\u76f8\u5173Nginx\u8c03\u4f18\u4ee5\u53ca\u5728\u8be5\u67b6\u6784\u4e0a\u589e\u52a0\u5185\u5bb9\uff0c\u90fd\u57fa\u4e8e\u5feb\u7167LAMP+Nginx\u96c6\u7fa4\u67b6\u6784-1 \u6765\u8fdb\u884c\u90e8\u7f72\u5b9e\u9a8c\u3002<\/strong><\/p>\n\n\n\n<p><strong>\u672c\u535a\u5ba2\u4e2dNginx\u76f8\u5173\u535a\u6587\uff0c\u90fd\u662f\u4ece\u5934\u5230\u5c3e\u76f8\u5173\u8054\u7684\uff0c\u9700\u8981\u8bfb\u8005\u4ece\u5934\u81f3\u5c3e\u9605\u8bfb\uff1b<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u6218\u5185\u5bb9\uff1a \u4f7f\u7528\u4e09\u53f0Linux\u670d\u52a1\u5668\uff0c\u4e00\u53f0\u8bbe\u5907\u5b89\u88c5Nginx\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\uff0c\u4e24\u53f0\u8bbe\u5907\u90e8\u7f72LAP\uff08\u53d1\u5e03\u4e24\u4e2a\u7f51\u7ad9wo&hellip; <a class=\"more-link\" href=\"https:\/\/www.charflower.com\/?p=2493\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">Nginx-\u96c6\u7fa4\u67b6\u6784-1-LANMP\u90e8\u7f72<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":2511,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[72],"tags":[45,92],"_links":{"self":[{"href":"https:\/\/www.charflower.com\/index.php?rest_route=\/wp\/v2\/posts\/2493"}],"collection":[{"href":"https:\/\/www.charflower.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.charflower.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.charflower.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.charflower.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2493"}],"version-history":[{"count":4,"href":"https:\/\/www.charflower.com\/index.php?rest_route=\/wp\/v2\/posts\/2493\/revisions"}],"predecessor-version":[{"id":2512,"href":"https:\/\/www.charflower.com\/index.php?rest_route=\/wp\/v2\/posts\/2493\/revisions\/2512"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.charflower.com\/index.php?rest_route=\/wp\/v2\/media\/2511"}],"wp:attachment":[{"href":"https:\/\/www.charflower.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.charflower.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.charflower.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}