{"id":1343,"date":"2022-05-13T00:16:48","date_gmt":"2022-05-12T16:16:48","guid":{"rendered":"http:\/\/www.tra56.com\/?p=1343"},"modified":"2022-05-13T00:16:48","modified_gmt":"2022-05-12T16:16:48","slug":"1343","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/1343.html","title":{"rendered":"\u57fa\u4e8e\u57df\u540d\u3001\u7aef\u53e3\u548cIP\u642d\u5efanginx\u865a\u62df\u4e3b\u673a"},"content":{"rendered":"

\u5982\u4f55\u642d\u5efanginx\u865a\u62df\u4e3b\u673a\uff1f\u8fd9\u4e2a\u95ee\u9898\u53ef\u80fd\u662f\u6211\u4eec\u65e5\u5e38\u5de5\u4f5c\u7ecf\u5e38\u89c1\u5230\u7684\u3002\u901a\u8fc7\u8fd9\u4e2a\u95ee\u9898\uff0c\u5e0c\u671b\u4f60\u80fd\u6536\u83b7\u66f4\u591a\u3002\u4e0b\u9762\u662f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u6b65\u9aa4\u5185\u5bb9\u3002<\/p>\n

Nginx\u652f\u6301\u7684\u865a\u62df\u4e3b\u673a\u6709\u4e09\u79cd<\/h3>\n

1\u3001\u57fa\u4e8e\u57df\u540d\u7684\u865a\u62df\u4e3b\u673a
2\u3001\u57fa\u4e8eIP\u7684\u865a\u62df\u4e3b\u673a
3\u3001\u57fa\u4e8e\u7aef\u53e3\u7684\u865a\u62df\u4e3b\u673a
\u4e14\u6bcf\u4e00\u79cd\u865a\u62df\u4e3b\u673a\u5747\u53ef\u901a\u8fc7\u201cserver{}" \u914d\u7f6e\u6bb5\u5b9e\u73b0\u5404\u81ea\u7684\u529f\u80fd<\/p>\n

\u4e00\u3001\u57fa\u4e8e\u57df\u540d\u642d\u5efa<\/h3>\n

1\u3001\u7f16\u8bd1\u5b89\u88c5Nginx\u670d\u52a1<\/strong>
2\u3001\u8fdc\u7a0b\u83b7\u53d6Windows\u4e0a\u7684\u6e90\u7801\u5305,\u5e76\u6302\u8f7d\u5230Linux\u4e0a<\/p>\n

[root@localhost ~]# smbclient -L \/\/192.168.235.1Enter SAMBA\\root's password: \r\nSharename       Type      Comment\r\n---------       ----      -------\r\nLNMP            Disk  \r\n\r\n[root@localhost ~]# mkdir \/abc\r\n[root@localhost ~]# mount.cifs \/\/192.168.235.1\/LNMP \/abc\r\nPassword for root@\/\/192.168.235.1\/LNMP:  \r\n[root@localhost ~]# ls \/abc\r\nDiscuz_X3.4_SC_UTF8.zip    nginx-1.12.0.tar.gz  php-7.1.10.tar.bz2\r\nmysql-boost-5.7.20.tar.gz  nginx-1.12.2.tar.gz  php-7.1.20.tar.gz<\/pre>\n

3\u3001\u89e3\u538b\u6e90\u7801\u5305\u3001\u4e0b\u8f7d\u5b89\u88c5\u7f16\u8bd1\u7ec4\u4ef6\u5305<\/span><\/p>\n

[root@localhost ~]# cd \/abc\r\n[root@localhost abc]# tar zxvf nginx-1.12.0.tar.gz -C \/opt\r\n[root@localhost abc]# ls \/opt\r\nnginx-1.12.0  rh\r\n[root@localhost abc]# cd \/opt\r\n[root@localhost opt]# yum install -y \\> \r\ngcc \\             \/\/C\u8bed\u8a00> \r\ngcc-c++ \\         \/\/c++\u8bed\u8a00> \r\npcre-devel \\      \/\/pcre\u8bed\u8a00\u5de5\u5177> \r\nzlib-devel        \/\/\u538b\u7f29\u51fd\u6570\u5e93<\/pre>\n

<\/span>4\u3001\u521b\u5efa\u7a0b\u5e8f\u7528\u6237\u5e76\u914d\u7f6eNginx\u670d\u52a1\u76f8\u5173\u7ec4\u4ef6<\/span><\/p>\n

[root@localhost opt]# useradd -M -s \/sbin\/nologin nginx\r\n\/\/\u521b\u5efa\u7a0b\u5e8f\u7528\u6237nginx,\u5e76\u9650\u5b9a\u5176\u4e0d\u53ef\u767b\u5f55\u7ec8\u7aef\r\n[root@localhost opt]# cd nginx-1.12.0\/\r\n[root@localhost nginx-1.12.0]# .\/configure \\            \r\n\/\/\u914d\u7f6enginx\r\n> --prefix=\/\/usr\/local\/nginx \\      \r\n\/\/\u6307\u5b9a\u5b89\u88c5\u8def\u5f84                        \r\n> --user=nginx \\\r\n\/\/\u6307\u5b9a\u7528\u6237\u540d\r\n> --group=nginx \\\r\n\/\/\u6307\u5b9a\u7528\u6237\u6240\u5c5e\u7ec4\r\n> --with-http_stub_status_module\r\n\/\/\u5b89\u88c5\u72b6\u6001\u7edf\u8ba1\u6a21\u5757<\/pre>\n

5\u3001\u7f16\u8bd1\u53ca\u5b89\u88c5<\/span><\/p>\n

[root@localhost nginx-1.12.0]# make && make install<\/pre>\n

6\u3001\u4f18\u5316Nginx\u670d\u52a1\u542f\u52a8\u811a\u672c,\u5e76\u5efa\u7acb\u547d\u4ee4\u8f6f\u8fde\u63a5<\/span><\/p>\n

[root@localhost nginx-1.12.0]# ln -s \/usr\/local\/nginx\/sbin\/nginx \/usr\/local\/sbin\/ \r\n\/\/\u521b\u5efanginx\u670d\u52a1\u547d\u4ee4\u8f6f\u94fe\u63a5\u5230\u7cfb\u7edf\u547d\u4ee4\r\n[root@localhost nginx-1.12.0]# systemctl stop firewalld.service \r\n\/\/\u5173\u95ed\u9632\u706b\u5899\r\n[root@localhost nginx-1.12.0]# setenforce 0\r\n\/\/\u5173\u95ed\u589e\u5f3a\u578b\u5b89\u5168\u529f\u80fd\r\n[root@localhost nginx-1.12.0]# nginx \r\n\/\/\u8f93\u5165nginx \u5f00\u542f\u670d\u52a1\r\n[root@localhost nginx-1.12.0]# netstat -ntap | grep 80      \/\/\u67e5\u770b\u670d\u52a1\u768480 \u7aef\u53e3,\u663e\u793a\u5df2\u5f00\u542f\r\ntcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7520\/nginx: master<\/pre>\n

1\u3001\u914d\u7f6eDNS<\/a>\u57df\u540d\u89e3\u6790\u670d\u52a1<\/strong><\/p>\n

[root@localhost ~]# yum -y install bind\r\n\/\/\u5b89\u88c5DNS\u670d\u52a1\u7684bind\u5305\r\n[root@localhost ~]# vim \/etc\/named.conf \r\n\/\/\u7f16\u8f91\u4e3b\u914d\u7f6e\u6587\u4ef6\r\n\r\noptions {\r\n        listen-on port 53 { any; };\r\n        ##\u5c06\u76d1\u542c\u5730\u5740127.0.0.1\u66ff\u6362\u4e3aany,\r\n        listen-on-v6 port 53 { ::1; };\r\n        directory       "\/var\/named";\r\n        dump-file       "\/var\/named\/data\/cache_dump.db";\r\n        statistics-file "\/var\/named\/data\/named_stats.txt";\r\n        memstatistics-file "\/var\/named\/data\/named_mem_stats.txt";\r\n        recursing-file  "\/var\/named\/data\/named.recursing";\r\n        secroots-file   "\/var\/named\/data\/named.secroots";\r\n        allow-query     { any; };\r\n        ##\u5c06\u6388\u6743localhost\u66ff\u6362\u4e3aany\r\n\r\n[root@localhost ~]# vim \/etc\/named.rfc1912.zones \r\n\/\/\u7f16\u8f91\u4e24\u4e2a\u57df\u540d\u7684\u533a\u57df\u914d\u7f6e\u6587\u4ef6\r\n\r\nzone "kgc.com" IN {        \r\n        type master;\r\n        file "kgc.com.zone";\r\n        allow-update { none; };\r\n};      \r\n\r\nzone "accp.com" IN {        \r\n        type master;\r\n        file "accp.com.zone";\r\n        allow-update { none; };\r\n};      \r\n\r\n[root@localhost ~]# cd \/var\/named\r\n[root@localhost named]# cp -p named.localhost kgc.com.zone \r\n[root@localhost named]# cp -p named.localhost accp.com.zone \r\n[root@localhost named]# vim kgc.com.zone \r\n\/\/\u7f16\u8f91kgc\u57df\u540d\u533a\u57df\u6570\u636e\u914d\u7f6e\u6587\u4ef6\r\n$TTL 1D\r\n@       IN SOA  @ rname.invalid. (\r\n                                        0       ; serial\r\n                                        1D      ; refresh\r\n                                        1H      ; retry\r\n                                        1W      ; expire\r\n                                        3H )    ; minimum\r\n        NS      @\r\n        A       127.0.0.1\r\nwww IN  A       192.168.235.158\r\n##\u5220\u9664\u539f\u6765\u672b\u884c\u7684\u5185\u5bb9,\u6dfb\u52a0\u57df\u540d\u89e3\u6790\u5730\u5740\u4e3a\u672c\u673a\u5730\u5740\r\n\r\n[root@localhost named]# vim accp.com.zone \r\n\/\/\u7f16\u8f91accp\u57df\u540d\u533a\u57df\u6570\u636e\u914d\u7f6e\u6587\u4ef6\r\n$TTL 1D\r\n@       IN SOA  @ rname.invalid. (\r\n                                        0       ; serial\r\n                                        1D      ; refresh\r\n                                        1H      ; retry\r\n                                        1W      ; expire\r\n                                        3H )    ; minimum\r\n        NS      @\r\n        A       127.0.0.1\r\nwww IN  A       192.168.235.158\r\n##\u5220\u9664\u539f\u6765\u672b\u884c\u7684\u5185\u5bb9,\u6dfb\u52a0\u57df\u540d\u89e3\u6790\u5730\u5740\u4e3a\u672c\u673a\u5730\u5740\r\n\r\n[root@localhost named]# systemctl start named   \r\n\/\/\u5f00\u542fdns\u670d\u52a1\r\n[root@localhost named]# systemctl stop firewalld.service    \r\n\/\/\u5173\u95ed\u9632\u706b\u5899\r\n[root@localhost named]# setenforce 0   \r\n\/\/\u5173\u95ed\u589e\u5f3a\u578b\u5b89\u5168\u529f\u80fd<\/pre>\n

1\u3001\u914d\u7f6e\u865a\u62df\u4e3b\u673a<\/strong>
2\u3001\u521b\u5efa\u81ea\u6d4b\u7f51\u9875<\/span><\/p>\n

[root@localhost named]# cd \r\n[root@localhost ~]# mkdir -p \/var\/www\/html\/kgc\r\n[root@localhost ~]# mkdir -p \/var\/www\/html\/accp\r\n[root@localhost ~]# ls \/var\/www\/html\/\r\naccp  kgc\r\n[root@localhost ~]# cd \/var\/www\/html\/\r\n[root@localhost html]# echo "this kgc web" > kgc\/index.html\r\n[root@localhost html]# echo "this accp web" > accp\/index.html<\/pre>\n

3\u3001\u7f16\u8f91nginx.conf\u914d\u7f6e\u6587\u4ef6<\/span><\/p>\n

[root@localhost html]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\n\r\nserver {\r\n        listen       80;\r\n        server_name  www.kgc.com;\r\n\r\n        charset utf-8;\r\n        ##\u652f\u6301\u4e2d\u6587\u5b57\u7b26\r\n        access_log  logs\/www.kgc.com.access.log;\r\n        ##kgc\u7ad9\u70b9\u8bbf\u95ee\u65e5\u5fd7\r\n        location \/ {\r\n        }\r\n        error_page   500 502 503 504  \/50x.html;\r\n        ##\u670d\u52a1\u7aef\u62a5\u9519\u76f8\u5173\u7f51\u9875\r\n        location = \/50x.html {\r\n            root   html;\r\n        }\r\n }\r\n\r\nserver {\r\n        listen       80;\r\n        server_name  www.accp.com;\r\n\r\n        charset utf-8;\r\n\r\n        access_log  logs\/www.accp.com.access.log;\r\n\r\n        location \/ {\r\n            root   \/var\/www\/html\/accp;\r\n            index  index.html index.htm;\r\n        }\r\n        error_page   500 502 503 504  \/50x.html;\r\n        location = \/50x.html {\r\n            root   html;\r\n        }\r\n }<\/pre>\n

4\u3001\u91cd\u8f7dNginx\u670d\u52a1<\/span><\/p>\n

[root@localhost ~]# killall -s HUP nginx\r\n[root@localhost ~]# netstat -ntap | grep 80\r\ntcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6117\/nginx: master<\/pre>\n

5\u3001\u6d4b\u8bd5\u7f51\u9875,\u8f93\u5165www .kgc. com \u4e0e www. accp. com\u4e24\u4e2a\u57df\u540d\u8fdb\u884c\u8bbf\u95ee<\/span><\/p>\n

\"image.png\"\/<\/span><\/p>\n

\"image.png\"\/<\/span><\/p>\n

<\/span><\/p>\n

\u4e8c\u3001\u57fa\u4e8e\u7aef\u53e3<\/h3>\n

1\u3001\u914d\u7f6e\u865a\u62df\u4e3b\u673a<\/strong>
2\u3001\u521b\u5efa\u53e6\u4e00\u4e2a\u7aef\u53e3\u7684\u6d4b\u8bd5\u7f51\u9875<\/p>\n

[root@localhost ~]# cd \/var\/www\/html\/\r\n[root@localhost html]# echo "this is kgc 8080 web" > kgc\/index.html<\/pre>\n

3\u3001\u7f16\u8f91nginx.conf\u914d\u7f6e\u6587\u4ef6,\u4ec5\u4fee\u6539\u76d1\u542c\u5730\u5740<\/span><\/p>\n

[root@localhost html]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\n\r\nserver {\r\n        listen 192.168.235.158:80;\r\n        ##\u76d1\u542c\u4e3b\u673a\u768480\u7aef\u53e3\r\n        server_name  www.kgc.com;\r\n\r\n        charset utf-8;\r\n\r\n        access_log  logs\/www.kgc.com.access.log;\r\n\r\n        location \/ {\r\n            root   \/var\/www\/html\/kgc;\r\n            index  index.html index.htm;\r\n        }\r\n        error_page   500 502 503 504  \/50x.html;\r\n        location = \/50x.html {\r\n            root   html;\r\n        }\r\n }\r\n\r\nserver {\r\n        listen 192.168.235.158:8080;\r\n        ##\u76d1\u542c\u4e3b\u673a\u76848080\u7aef\u53e3\r\n        server_name  www.kgc.com;\r\n\r\n        charset utf-8;\r\n\r\n        access_log  logs\/www.kgc.com.access.log;\r\n\r\n        location \/ {\r\n            root   \/var\/www\/html\/kgc;\r\n            index  index.html index.htm;\r\n        }\r\n        error_page   500 502 503 504  \/50x.html;\r\n        location = \/50x.html {\r\n            root   html;\r\n        }\r\n }<\/pre>\n


<\/span>4\u3001\u91cd\u8f7dNginx\u670d\u52a1<\/span><\/p>\n

[root@localhost html]# killall -s HUP nginx\r\n[root@localhost html]# netstat -ntap | grep 80\r\ntcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      41958\/nginx: master<\/pre>\n

\"image.png\"\/<\/p>\n

\u4e09\u3001\u57fa\u4e8eIP<\/h3>\n

1\u3001\u6dfb\u52a0\u7f51\u5361,\u5e76\u89c4\u5212\u597dIP
\u4e3b\u673aIP  :192.168.235.158  \uff1b  192.168.235.142
\u57df\u540d     \uff1awww . kgc . com \uff1b  www . accp . com<\/strong>
2\u3001\u4fee\u6539accp\u57df\u540d\u7684\u533a\u57df\u6570\u636e\u6587\u4ef6\u914d\u7f6e<\/p>\n

[root@localhost ~]# vim \/var\/named\/accp.com.zone\r\n\r\n$TTL 1D\r\n@       IN SOA  @ rname.invalid. (\r\n                                        0       ; serial\r\n                                        1D      ; refresh\r\n                                        1H      ; retry\r\n                                        1W      ; expire\r\n                                        3H )    ; minimum\r\n        NS      @\r\n        A       127.0.0.1\r\nwww IN  A       192.168.235.142\r\n##\u66f4\u6539IP\u5730\u5740\u4e3a 192.168.235.142\r\n\r\n[root@localhost ~]# systemctl restart named\r\n##\u91cd\u542f\u57df\u540d\u89e3\u6790\u670d\u52a1<\/pre>\n

3\u3001\u7f16\u8f91nginx.conf\u914d\u7f6e\u6587\u4ef6<\/span><\/p>\n

[root@localhost ~]# vim \/usr\/local\/nginx\/conf\/nginx.conf\r\n##\u6b64\u6bb5\u4e0d\u505a\u4fee\u6539\r\nserver {\r\n        listen 192.168.235.158:80;\r\n        server_name  www.kgc.com;\r\n\r\n        charset utf-8;\r\n\r\n        access_log  logs\/www.kgc.com.access.log;\r\n\r\n        location \/ {\r\n            root   \/var\/www\/html\/kgc;\r\n            index  index.html index.htm;\r\n        }\r\n        error_page   500 502 503 504  \/50x.html;\r\n        location = \/50x.html {\r\n            root   html;\r\n        }\r\n }\r\n\r\nserver {\r\n         listen 192.168.235.142:80;\r\n         ##\u4fee\u6539\u672c\u6bb5\u76d1\u542c\u5730\u5740\u4e3a192.168.234.142\r\n         server_name  www.accp.com;\r\n\r\n         charset utf-8;\r\n\r\n         access_log  logs\/www.accp.com.access.log;\r\n\r\n         location \/ {\r\n             root   \/var\/www\/html\/accp;\r\n             index  index.html index.htm;\r\n         }\r\n         error_page   500 502 503 504  \/50x.html;\r\n         location = \/50x.html {\r\n             root   html;\r\n         }\r\n  }<\/pre>\n

4\u3001\u91cd\u8f7dNginx\u670d\u52a1<\/span><\/p>\n

[root@localhost ~]# killall -s HUP nginx\r\n[root@localhost ~]# netstat -ntap | grep 80\r\ntcp        0      0 192.168.235.142:80      0.0.0.0:*               LISTEN      7299\/nginx: master  \r\ntcp        0      0 192.168.235.158:80      0.0.0.0:*               LISTEN      7299\/nginx: master<\/pre>\n

5\u3001\u6d4b\u8bd5\u7f51\u9875,\u5206\u522b\u8f93\u5165IP\u5730\u5740192.168.235.158\u548c192.168.235.142\u8fdb\u884c\u8bbf\u95ee<\/span><\/p>\n

\"image.png\"\/<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5982\u4f55\u642d\u5efanginx\u865a\u62df\u4e3b\u673a\uff1f\u8fd9\u4e2a\u95ee\u9898\u53ef\u80fd\u662f\u6211\u4eec\u65e5\u5e38\u5de5\u4f5c\u7ecf\u5e38\u89c1\u5230\u7684\u3002\u901a\u8fc7\u8fd9\u4e2a\u95ee\u9898\uff0c\u5e0c\u671b\u4f60\u80fd\u6536\u83b7\u66f4\u591a\u3002\u4e0b\u9762\u662f\u89e3\u51b3\u8fd9 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,95],"tags":[],"class_list":["post-1343","post","type-post","status-publish","format-standard","hentry","category-linux","category-nginx"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/1343"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=1343"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/1343\/revisions"}],"predecessor-version":[{"id":1344,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/1343\/revisions\/1344"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=1343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=1343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=1343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}