{"id":32776,"date":"2024-01-20T14:16:16","date_gmt":"2023-03-31T21:15:40","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/"},"modified":"2024-05-04T19:16:33","modified_gmt":"2024-05-04T11:16:33","slug":"%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/","title":{"rendered":"\u6574\u7406\u4e86Nginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cIP\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\u8003\u8651\u5230ELB\u7684\u5b58\u5728\u4e0e\u5426\uff09"},"content":{"rendered":"<h1>\u9996\u5148<\/h1>\n<p>\u6211\u6574\u7406\u4e86\u5173\u4e8eNginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u4ee5\u53caIP\u9650\u5236\uff08\u4e5f\u8003\u8651\u5230Elastic Load Balancer\u7684\u60c5\u51b5\uff09\u7684\u914d\u7f6e\u65b9\u6cd5\u3002<\/p>\n<p>\u6211\u8fd8\u4e3aAWS EC2\u7684Amazon Linux2\u548cWindows\u670d\u52a1\u5668\u63d0\u4f9b\u4e86\u4e24\u79cd\u914d\u7f6e\u65b9\u6cd5\u7684\u603b\u7ed3\u3002<\/p>\n<h2>IP\u9650\u5236\u7684\u524d\u63d0\u6761\u4ef6 (IP de<\/h2>\n<p>111.111.111.111\u548c222.222.222.222\u662f\u5141\u8bb8\u7684IP\u5730\u5740<br \/>\n\u5176\u4ed6\u6240\u6709IP\u5730\u5740\u90fd\u8981\u88ab\u62d2\u7edd<\/p>\n<p>10.0.0.0\/16 = \u4f7f\u7528Elastic Load Balancer\uff08ELB\uff09\u7684\u865a\u62df\u79c1\u6709\u4e91\u7684 IP \u5730\u5740\u8303\u56f4\uff08IPv4 CIDR \u7b49\uff09<br \/>\n#IP\u9650\u5236\uff08\u4f7f\u7528ELB\u65f6\uff09<\/p>\n<h3>\u5f53\u4f7f\u7528ELB\u65f6\uff0c\u66ff\u4ee3\u65b9\u6848\u662fNginx\u3002<\/h3>\n<pre class=\"post-pre\"><code><span class=\"k\">server<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">listen<\/span> <span class=\"mi\">80<\/span><span class=\"p\">;<\/span>\r\n \r\n    <span class=\"kn\">set_real_ip_from<\/span> <span class=\"mi\">10<\/span><span class=\"s\">.0.0.0\/16<\/span><span class=\"p\">;<\/span> <span class=\"c1\"># ELB\u3092\u8a2d\u7f6e\u3057\u3066\u3044\u308bVPC\u306eIP\u30a2\u30c9\u30ec\u30b9\u3092\u6307\u5b9a<\/span>\r\n    <span class=\"kn\">real_ip_header<\/span>  <span class=\"s\">X-Forwarded-For<\/span><span class=\"p\">;<\/span>\r\n\r\n    <span class=\"kn\">location<\/span> <span class=\"n\">\/\u5236\u9650\u5148\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\/<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">allow<\/span> <span class=\"mi\">111<\/span><span class=\"s\">.111.111.111<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">allow<\/span> <span class=\"mi\">222<\/span><span class=\"s\">.222.222.222<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">deny<\/span> <span class=\"s\">all<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u7531\u4e8e\u670d\u52a1\u5668\u662f\u4eceELB\u8bbf\u95ee\u7684\uff0c\u6240\u4ee5\u9700\u8981\u5c06ELB\u7684IP\u66ff\u6362\u4e3a\u5ba2\u6237\u7aef\u7684IP\u3002<br \/>\n\u56e0\u6b64\uff0c\u9700\u8981\u5728set_real_ip_from\u4e2d\u6307\u5b9a\u5b89\u88c5ELB\u7684VPC\u7684IP\u5730\u5740\uff0c\u5e76\u5728X-Forwarded-For\u4e2d\u5b58\u50a8\u5ba2\u6237\u7aef\u7684IP\uff0c\u4ece\u800c\u5728real_ip_header\u4e2d\u8bbe\u7f6e\u8be5\u503c\u3002<br \/>\n\u5982\u679c\u60f3\u8981\u6309\u670d\u52a1\u5668\u800c\u4e0d\u662f\u76ee\u5f55\u9650\u5236\u6743\u9650\uff0c\u53ef\u4ee5\u5728server {}\u5185\u653e\u7f6eallow\u548cdeny\u3002<\/p>\n<p>\u7b80\u6613\u6784\u6210\u56fe<br \/>\n\u00b7 \u901a\u5e38<br \/>\n\u5ba2\u6237\u7aefIP(xxx&#8230;)\u2192\u8d1f\u8f7d\u5747\u8861\u5668IP(yyy&#8230;)\u2192\u670d\u52a1\u5668<br \/>\n\u670d\u52a1\u5668\u5bf9\u4e8eyyy&#8230;\u8bbe\u5b9aIP\u9650\u5236<\/p>\n<p>\u5f53\u4f7f\u7528X-Forwarded-For\u65f6\uff0c<br \/>\n\u5ba2\u6237\u7aefIP\uff08xxx&#8230;\uff09\u2192 ELB IP\uff08xxx&#8230;\u548cyyy&#8230;\uff09\u2192 \u670d\u52a1\u5668<br \/>\n\u670d\u52a1\u5668\u5bf9xxx&#8230;\u8fdb\u884cIP\u9650\u5236\u3002<\/p>\n<h3>\u5f53\u4f7f\u7528Apache\uff08\u5728ELB\u4e0a\uff09\u65f6<\/h3>\n<pre class=\"post-pre\"><code><span class=\"nc\">SetEnvIf<\/span> <span class=\"ss\">X-Forwarded-For<\/span> \"111\\.111\\.111\\.111\" allowedip\r\n<span class=\"nc\">SetEnvIf<\/span> <span class=\"ss\">X-Forwarded-For<\/span> \"222\\.222\\.222\\.222\" allowedip\r\n<span class=\"nc\">order<\/span> deny,allow\r\n<span class=\"nc\">deny<\/span> <span class=\"ss\">from<\/span> <span class=\"ss\">all<\/span>\r\n<span class=\"nc\">allow<\/span> <span class=\"ss\">from<\/span> env=allowedip\r\n<\/code><\/pre>\n<p>\u7531\u4e8eX-Forwarded-For\u5305\u542b\u5ba2\u6237\u7aefID\uff0c\u56e0\u6b64\u9700\u8981\u6307\u5b9a\u8981\u5141\u8bb8\u7684IP\u5730\u5740\u3002<br \/>\n\u53e6\u5916\uff0c\u4e3a\u4e86\u8fdb\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\uff0c\u9700\u8981\u5bf9\u53e5\u70b9\u8fdb\u884c\u8f6c\u4e49\u3002<br \/>\n\u672c\u6b21\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5c06\u5728.htaccess\u6587\u4ef6\u4e2d\u8fdb\u884c\u8bbe\u7f6e\uff0c.htaccess\u53ef\u4ee5\u5bf9\u6bcf\u4e2a\u76ee\u5f55\u8fdb\u884c\u9650\u5236\u3002<br \/>\n\u5982\u679c\u60f3\u8981\u5bf9\u6574\u4e2aApache\u8fdb\u884c\u9650\u5236\uff0c\u5219\u5e94\u8be5\u5c06\u5176\u914d\u7f6e\u5728apache2.conf\uff08httpd.conf\uff09\u4e2d\u3002<\/p>\n<h1>\u53ea\u9650\u5236IP\u5730\u5740\uff08\u4e0d\u4f7f\u7528\u8d1f\u8f7d\u5747\u8861\u5668ELB\uff09<\/h1>\n<h3>Nginx\uff08\u4e0d\u4f7f\u7528ELB\uff09<\/h3>\n<pre class=\"post-pre\"><code><span class=\"k\">server<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">listen<\/span> <span class=\"mi\">80<\/span><span class=\"p\">;<\/span>\r\n\r\n    <span class=\"kn\">allow<\/span> <span class=\"mi\">111<\/span><span class=\"s\">.111.111.111<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">allow<\/span> <span class=\"mi\">222<\/span><span class=\"s\">.222.222.222<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">deny<\/span> <span class=\"s\">all<\/span><span class=\"p\">;<\/span>\r\n \r\n    <span class=\"kn\">location<\/span> <span class=\"n\">\/<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u6211\u5011\u5df2\u7d93\u5728\u4f3a\u670d\u5668\u5c64\u9762\u9032\u884c\u4e86\u9650\u5236\u3002\u53ea\u9700\u8981\u4f7f\u7528\u300c\u5141\u8a31\uff08allow\uff09\u300d\u548c\u300c\u62d2\u7d55\uff08deny\uff09\u300d\uff0c\u5982\u679c\u8981\u5728\u76ee\u9304\u5c64\u9762\u9032\u884c\u9650\u5236\uff0c\u53ea\u9700\u628a\u5b83\u653e\u5165\u76ee\u9304\u5167\u5373\u53ef\u3002<\/p>\n<h3>Apache\uff08\u672a\u4f7f\u7528 ELB\uff09<\/h3>\n<pre class=\"post-pre\"><code><span class=\"c\"># 2.2\u7cfb\u4ee5\u524d\u306eApache<\/span>\r\n<span class=\"nc\">Order<\/span> deny,allow\r\n<span class=\"nc\">Deny<\/span> <span class=\"ss\">from<\/span> <span class=\"ss\">all<\/span>\r\n<span class=\"nc\">Allow<\/span> <span class=\"ss\">from<\/span> 111.111.111.111\r\n<span class=\"nc\">Allow<\/span> <span class=\"ss\">from<\/span> 222.222.222.222\r\n\r\n<span class=\"c\"># 2.4\u7cfb\u4ee5\u964d\u306eApache<\/span>\r\n<span class=\"nc\">Require<\/span> <span class=\"ss\">all<\/span> denied\r\n<span class=\"nc\">Require<\/span> ip 111.111.111.111\r\n<span class=\"nc\">Require<\/span> ip 222.222.222.222\r\n<\/code><\/pre>\n<p>Apache\u7684\u7248\u672c\uff0c\u5176\u5199\u6cd5\u56e0\u7248\u672c\u800c\u5f02\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528httpd -v\u547d\u4ee4\u8fdb\u884c\u786e\u8ba4\u3002<\/p>\n<h1>\u57fa\u672c\u8ba4\u8bc1<\/h1>\n<h3>Nginx\uff08\u5bf9\u6240\u6709\u8bbf\u95ee\u9002\u7528\uff09<\/h3>\n<p>\u5c06\u5fc5\u8981\u7684\u914d\u7f6e\u5185\u5bb9\u8bb0\u5f55\u5728nginx.conf\u6587\u4ef6\u4e2d\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"k\">server<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">listen<\/span>       <span class=\"mi\">80<\/span><span class=\"p\">;<\/span>\r\n\r\n    <span class=\"kn\">auth_basic<\/span> <span class=\"s\">\"Restricted\"<\/span><span class=\"p\">;<\/span><span class=\"kn\">\u3000\u3000\u3000\u3000<\/span><span class=\"c1\"># \u8a8d\u8a3c\u6642\u306b\u8868\u793a\u3055\u308c\u308b\u30e1\u30c3\u30bb\u30fc\u30b8<\/span>\r\n    <span class=\"s\">auth_basic_user_file<\/span> <span class=\"n\">\/etc\/nginx\/.htpasswd<\/span><span class=\"p\">;<\/span><span class=\"kn\">\u3000\u3000<\/span><span class=\"c1\"># .htpasswd\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9<\/span>\r\n<span class=\"err\">}<\/span>\r\n<\/code><\/pre>\n<p>\u4fee\u6539\u5b8cnginx.conf\u6587\u4ef6\u540e\uff0c\u8981\u8fdb\u884c\u8bed\u6cd5\u68c0\u67e5\u5e76\u91cd\u65b0\u542f\u52a8\u3002<\/p>\n<pre class=\"post-pre\"><code>$ nginx -t -c \/etc\/nginx\/nginx.conf \r\n$ sudo nginx -s reload\r\n<\/code><\/pre>\n<h3>\u5728Nginx\u4e2d(\u4ec5\u9002\u7528\u4e8e\u4e00\u90e8\u5206\u8bbf\u95ee)<\/h3>\n<p>\u8fd9\u662f\u53ea\u5bf9index.php\u5e94\u7528\u57fa\u672c\u8ba4\u8bc1\u7684\u6a21\u5f0f\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"k\">server<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">listen<\/span> <span class=\"mi\">80<\/span><span class=\"p\">;<\/span>\r\n\r\n    <span class=\"kn\">location<\/span> <span class=\"n\">\/index.php<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">auth_basic<\/span> <span class=\"s\">\"Restricted\"<\/span><span class=\"p\">;<\/span>                   <span class=\"c1\"># \u8a8d\u8a3c\u6642\u306b\u8868\u793a\u3055\u308c\u308b\u30e1\u30c3\u30bb\u30fc\u30b8<\/span>\r\n        <span class=\"kn\">auth_basic_user_file<\/span> <span class=\"n\">\/etc\/nginx\/.htpasswd<\/span><span class=\"p\">;<\/span> <span class=\"c1\"># .htpasswd\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>$ nginx -t -c \/etc\/nginx\/nginx.conf \r\n$ sudo nginx -s reload\r\n<\/code><\/pre>\n<h3>Nginx\uff08\u9664\u53bb\u4e00\u90e8\u5206\uff0c\u9002\u7528\u4e8e\u6240\u6709\u8bbf\u95ee\uff09<\/h3>\n<p>\u8fd9\u662f\u53ea\u5bf9index.php\u4e0d\u8fdb\u884c\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u7684\u6a21\u5f0f\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"k\">server<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">listen<\/span> <span class=\"mi\">80<\/span><span class=\"p\">;<\/span>\r\n\r\n    <span class=\"kn\">auth_basic<\/span> <span class=\"s\">\"Restricted\"<\/span><span class=\"p\">;<\/span><span class=\"kn\">\u3000\u3000\u3000\u3000<\/span><span class=\"c1\"># \u8a8d\u8a3c\u6642\u306b\u8868\u793a\u3055\u308c\u308b\u30e1\u30c3\u30bb\u30fc\u30b8<\/span>\r\n    <span class=\"s\">auth_basic_user_file<\/span> <span class=\"n\">\/etc\/nginx\/.htpasswd<\/span><span class=\"p\">;<\/span><span class=\"kn\">\u3000\u3000<\/span><span class=\"c1\"># .htpasswd\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9<\/span>\r\n\r\n    <span class=\"s\">location<\/span> <span class=\"n\">\/index.php<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">satisfy<\/span> <span class=\"s\">any<\/span><span class=\"p\">;<\/span>  <span class=\"c1\"># IP\u5236\u9650 \u307e\u305f\u306f Basic\u8a8d\u8a3c\u306e\u3044\u305a\u308c\u304b\u304cOK\u306a\u3089\u901a\u3059\u8a2d\u5b9a<\/span>\r\n        <span class=\"kn\">allow<\/span>   <span class=\"s\">all<\/span><span class=\"p\">;<\/span>  <span class=\"c1\"># \u3059\u3079\u3066\u8a31\u53ef<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>$ nginx -t -c \/etc\/nginx\/nginx.conf \r\n$ sudo nginx -s reload\r\n<\/code><\/pre>\n<h1>\u57fa\u672c\u8ba4\u8bc1\uff08ELB\u4e0d\u4f7f\u7528\uff09<\/h1>\n<h3>\u5982\u679c\u4e0d\u4f7f\u7528ELB\uff0c\u8bf7\u5728.htaccess\u4e2d\u8f93\u5165Apache + Windows\u3002<\/h3>\n<pre class=\"post-pre\"><code><span class=\"nc\">AuthUserFile<\/span> C:\\Apache24\\htpasswd\\.htpasswd\r\n<span class=\"nc\">AuthGroupfile<\/span> \/dev\/null\r\n<span class=\"nc\">AuthName<\/span> \"TEST WEB\"\r\n<span class=\"nc\">AuthType<\/span> <span class=\"ss\">Basic<\/span>\r\n<span class=\"nc\">require<\/span> valid-user\r\n<\/code><\/pre>\n<h3>\u5982\u679c\u4e0d\u4f7f\u7528ELB\uff0c\u5219\u5c06Apache + EC2\u7684\u914d\u7f6e\u4fe1\u606f\u5199\u5165.htaccess\u6587\u4ef6\u3002<\/h3>\n<pre class=\"post-pre\"><code><span class=\"p\">&lt;<\/span><span class=\"nl\">RequireAny<\/span><span class=\"p\">&gt;\r\n<\/span>    <span class=\"nc\">AuthUserFile<\/span> \/home\/xxxx\/htpasswd\/.htpasswd\r\n    <span class=\"nc\">AuthName<\/span> \"Please enter your ID <span class=\"ss\">and<\/span> password\"\r\n    <span class=\"nc\">AuthType<\/span> <span class=\"ss\">Basic<\/span>\r\n\r\n    <span class=\"nc\">Require<\/span> valid-user\r\n<span class=\"p\">&lt;\/<\/span><span class=\"nl\">RequireAny<\/span><span class=\"p\">&gt;\r\n<\/span>\r\n<span class=\"p\">&lt;<\/span><span class=\"nl\">Files<\/span><span class=\"sr\"> ~ \"^\\.(htaccess|htpasswd)$\"<\/span><span class=\"p\">&gt;\r\n<\/span>    <span class=\"nc\">Require<\/span> <span class=\"ss\">all<\/span> denied\r\n<span class=\"p\">&lt;\/<\/span><span class=\"nl\">Files<\/span><span class=\"p\">&gt;\r\n<\/span><\/code><\/pre>\n<p>AuthUserFile\u662f\u6307\u5b8c\u6574\u8def\u5f84\u540d\u4e3a.htpasswd\u7684\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u5305\u542bBasic\u8ba4\u8bc1\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002<br \/>\nAuthName\u662f\u5728\u8ba4\u8bc1\u65f6\u663e\u793a\u7684\u6d88\u606f\u3002<br \/>\nAuthType\u662f\u8ba4\u8bc1\u7c7b\u578b\u7684\u9009\u62e9\u3002\u9009\u62e9Basic\u8868\u793a\u4f7f\u7528BASIC\u8ba4\u8bc1\u3002<br \/>\nrequire valid-user\u8868\u793a\u5141\u8bb8\u7ecf\u8fc7\u8ba4\u8bc1\u7684\u6240\u6709\u7528\u6237\u8bbf\u95ee\u3002<\/p>\n<p>\u7531\u4e8e\u4e0d\u5e0c\u671b\u516c\u5f00\u663e\u793a.htpasswd\u6587\u4ef6\uff0c\u90e8\u5206\u5c06\u4e0d\u4e88\u5217\u51fa\u3002\u6b64\u90e8\u5206\u975e\u5f3a\u5236\u3002<\/p>\n<pre class=\"post-pre\"><code>aaaaa:$apr1$pzWRunvc$tq0UpVBXVjSJjLnLM9LGY.\r\n<\/code><\/pre>\n<p>\u5728.htpasswd\u6587\u4ef6\u4e2d\uff0c\u5c06Basic\u8ba4\u8bc1\u6240\u9700\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u4ee5\u7528\u6237\u540d:\u7ecf\u8fc7\u54c8\u5e0c\u8fd0\u7b97\u7684\u5bc6\u7801\u7684\u5f62\u5f0f\u8fdb\u884c\u8bb0\u5f55\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u5728\u8fd9\u4e2a\u7f51\u7ad9\u4e0a\u81ea\u52a8\u751f\u6210\u7528\u4e8eBasic\u8ba4\u8bc1\u7684.htaccess\u548c.htpasswd\u6587\u4ef6\u3002<\/p>\n<p>AuthGroupFile \/dev\/null\u6307\u5b9a\u5141\u8bb8\u6bcf\u4e2a\u7ec4\u8bbf\u95ee\u3002 &#8220;\/dev\/null&#8221;\u8868\u793a\u8fd9\u6837\u7684\u6587\u4ef6\u4e0d\u5b58\u5728\u3002\u5373\u8868\u793a\u4e0d\u9650\u5236\u6bcf\u4e2a\u7ec4\u7684\u8bbf\u95ee\u3002<\/p>\n<p>\u5982\u679c\u5728\u7279\u5b9a\u7684\u670d\u52a1\u5668\u4e0a\u8fdb\u884c\u8bb0\u5f55\u4f1a\u51fa\u73b0\u9519\u8bef\u7684\u60c5\u51b5\u4e0b\uff0c\u8bf7\u4e0d\u8981\u8fdb\u884c\u8bb0\u5f55\u3002<\/p>\n<h2>\u5982\u679c\u4e0d\u4f7f\u7528ELB\uff0c\u5219\u5728httpd.conf\u4e2d\u6dfb\u52a0Apache + EC2\u7684\u914d\u7f6e\u3002<\/h2>\n<p>\u5982\u679c\u5c06\u76ee\u5f55\u8bbe\u7f6e\u4e3a\/var\/www\/html<\/p>\n<pre class=\"post-pre\"><code>&lt;<span class=\"n\">Directory<\/span> <span class=\"s2\">\"\/var\/www\/html\"<\/span>&gt;\r\n    <span class=\"n\">Options<\/span> <span class=\"n\">FollowSymLinks<\/span>\r\n    <span class=\"n\">AllowOverride<\/span> <span class=\"n\">All<\/span>\r\n\r\n    <span class=\"n\">AuthType<\/span> <span class=\"n\">Basic<\/span>\r\n    <span class=\"n\">AuthName<\/span> <span class=\"s2\">\"basic auth\"<\/span>\r\n    <span class=\"n\">AuthUserfile<\/span> \/<span class=\"n\">etc<\/span>\/<span class=\"n\">httpd<\/span>\/<span class=\"n\">conf<\/span>\/.<span class=\"n\">htpasswd<\/span>\r\n    <span class=\"n\">Require<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">user<\/span>\r\n&lt;\/<span class=\"n\">Directory<\/span>&gt;\r\n<\/code><\/pre>\n<p>\u5728\u4e2d\u56fd\u5883\u5185\uff0cAuthUserfile\u7684\u5bc6\u7801\u8def\u5f84\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u90fd\u53ef\u4ee5\u3002<\/p>\n<p>\u4fee\u590d\u5b8c httpd.conf \u6587\u4ef6\u540e\uff0c\u8bf7\u91cd\u65b0\u542f\u52a8 Apache \u670d\u52a1\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"gp\">$<\/span> systemctl restart httpd.service\r\n<\/code><\/pre>\n<h3>\u5982\u679c\u4e0d\u4f7f\u7528ELB\uff0c\u5e76\u4e14\u9700\u8981\u5728httpd.conf\u4e2d\u8fdb\u884c\u914d\u7f6e\uff0c\u90a3\u4e48Apache + Windows Server\u53ef\u4ee5\u5982\u4e0b\u8868\u8ff0\uff1a<\/h3>\n<p>\u7531\u4e8e\u5728Windows\u670d\u52a1\u5668\u4e0a\u65e0\u6cd5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u56e0\u6b64\u8bf7\u5728httpd.conf\u6587\u4ef6\u4e2d\u5b8c\u6210\u914d\u7f6e\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u6709\u5173\u4f4d\u7f6e\u7684\u8be6\u7ec6\u8bf4\u660e\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><span class=\"c\">#Basic Auth\r\n<\/span>&lt;<span class=\"n\">Location<\/span> <span class=\"s2\">\"\/\"<\/span>&gt;\r\n    <span class=\"n\">AuthType<\/span> <span class=\"n\">Basic<\/span>\r\n    <span class=\"n\">AuthName<\/span> <span class=\"s2\">\"test basic auth\"<\/span>\r\n    <span class=\"n\">AuthUserFile<\/span> <span class=\"s2\">\"C:\\Apache24\\htpasswd\\.htpasswd\"<\/span>\r\n    <span class=\"n\">Require<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">user<\/span>\r\n&lt;\/<span class=\"n\">Location<\/span>&gt;\r\n<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u5728\u201c\u4f4d\u7f6e\u201d\u4e2d\u9009\u62e9\u8981\u8fdb\u884c\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff0c\u672c\u6b21\u9009\u62e9\u7684\u8def\u5f84\u662f&#8221;\/&#8221;\uff0c\u5982\u679c\u60a8\u586b\u5199\u4e3a&#8221;\/index.php&#8221;\uff0c\u5219\u53ea\u6709index.php\u4f1a\u8fdb\u884c\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u3002<\/p>\n<p>\u5bc6\u7801\u7684\u521b\u5efa\u65b9\u6cd5\u4e0e\u4e4b\u524d\u7684\u65b9\u6cd5\u76f8\u540c\u3002<br \/>\n.htpasswd\u5e94\u8be5\u653e\u7f6e\u5728\u9002\u5f53\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u7136\u540e\uff0c\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u91cd\u65b0\u542f\u52a8Apache\u3002<\/p>\n<pre class=\"post-pre\"><code>C:\\Apache24\\bin&gt; httpd -k restart\r\n<\/code><\/pre>\n<h1>\u57fa\u672c\u8ba4\u8bc1\uff08\u901a\u8fc7ELB\u4f7f\u7528\u5e76\u901a\u8fc7\u5065\u5eb7\u68c0\u67e5\uff09<\/h1>\n<h2>Nginx<\/h2>\n<h3>\u5728\u4f7f\u7528ELB\u65f6\uff0c\u5c06\u6d41\u91cf\u5f15\u5bfc\u81f3Nginx\u5e76\u8fdb\u884c\u5065\u5eb7\u68c0\u67e5\u3002<\/h3>\n<p>\u5728\u6240\u6709\u8def\u5f84\u4e0a\u90fd\u8fdb\u884c\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u3002<br \/>\n\u914d\u7f6e\u5728nginx.conf\u6587\u4ef6\u4e2d\uff0c\u5e76\u5c06.htpasswd\u6587\u4ef6\u653e\u7f6e\u5728\/etc\/nginx\/\u76ee\u5f55\u4e0b\u3002<br \/>\n\u53ea\u6709\u5065\u5eb7\u68c0\u67e5\u4f1a\u901a\u8fc7\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">server<\/span> {\r\n  <span class=\"n\">listen<\/span> <span class=\"m\">80<\/span>;\r\n\r\n  <span class=\"n\">if<\/span> ($<span class=\"n\">http_user_agent<\/span> = <span class=\"s2\">\"ELB-HealthChecker\/*\"<\/span>) {\r\n    <span class=\"n\">set<\/span> $<span class=\"n\">auth<\/span> <span class=\"n\">off<\/span>;\r\n  }\r\n\r\n  <span class=\"n\">location<\/span> \/ {\r\n    <span class=\"n\">auth_basic<\/span> $<span class=\"n\">auth<\/span>;\r\n    <span class=\"n\">auth_basic_user_file<\/span> \/<span class=\"n\">etc<\/span>\/<span class=\"n\">nginx<\/span>\/.<span class=\"n\">htpasswd<\/span>; <span class=\"c\"># .htpasswd\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\r\n<\/span>  }\r\n<\/code><\/pre>\n<h3>\u5728\u4f7f\u7528ELB\u65f6\uff0c\u6392\u9664\u7279\u5b9a\u8def\u5f84\u7684\u65b9\u5f0f\u662f\u901a\u8fc7Nginx\u6765\u5b9e\u73b0\u3002<\/h3>\n<p>\u9664\u4e86\/test\/\u8def\u5f84\uff0c\u5176\u4ed6\u90fd\u9700\u8981\u8fdb\u884c\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u3002\u5c06.htpasswd\u6587\u4ef6\u653e\u7f6e\u5728\/etc\/nginx\/\u76ee\u5f55\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">server<\/span> {\r\n  <span class=\"n\">listen<\/span> <span class=\"m\">80<\/span>;\r\n\r\n  <span class=\"n\">if<\/span> ($<span class=\"n\">http_user_agent<\/span> = <span class=\"s2\">\"ELB-HealthChecker\/*\"<\/span>) {\r\n    <span class=\"n\">set<\/span> $<span class=\"n\">auth<\/span> <span class=\"n\">off<\/span>;\r\n  }\r\n\r\n  <span class=\"n\">location<\/span> \/<span class=\"n\">test<\/span>\/ {\r\n    <span class=\"n\">try_files<\/span> $<span class=\"n\">uri<\/span> $<span class=\"n\">uri<\/span>\/ \/<span class=\"n\">index<\/span>.<span class=\"n\">php<\/span>?$<span class=\"n\">query_string<\/span>;\r\n    <span class=\"n\">satisfy<\/span> <span class=\"n\">any<\/span>;\r\n    <span class=\"n\">allow<\/span>   <span class=\"n\">all<\/span>;\r\n  }\r\n\r\n  <span class=\"n\">location<\/span> \/ {\r\n    <span class=\"n\">auth_basic<\/span> $<span class=\"n\">auth<\/span>;\r\n    <span class=\"n\">auth_basic_user_file<\/span> \/<span class=\"n\">etc<\/span>\/<span class=\"n\">nginx<\/span>\/.<span class=\"n\">htpasswd<\/span>;\r\n  }\r\n<\/code><\/pre>\n<h2>Apache \u53ef\u4ee5\u88ab\u89e3\u91ca\u4e3a\u963f\u5e15\u5947\u3002<\/h2>\n<h3>\u5f53\u4f7f\u7528Apache\u548cEC2\uff08\u5728ELB\u4e0a\uff09\u65f6\uff0c\u5728.htaccess\u4e2d\u8fdb\u884c\u914d\u7f6e\u3002<\/h3>\n<p>\u8bbe\u7f6e\u4ec5\u901a\u8fc7ELB\u7684\u5065\u5eb7\u68c0\u67e5\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"c\"># \u30ea\u30af\u30a8\u30b9\u30c8URL\u304c\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u5148\u306e\u5834\u5408\u306f\u3001\u30a2\u30af\u30bb\u30b9\u3092\u8a31\u53ef<\/span>\r\n<span class=\"nc\">SetEnvIf<\/span> User-Agent \"^ELB-HealthChecker.*$\" healthcheck\r\n\r\n<span class=\"p\">&lt;<\/span><span class=\"nl\">RequireAny<\/span><span class=\"p\">&gt;\r\n<\/span>    <span class=\"nc\">AuthUserFile<\/span> \/home\/xxxxx\/htpasswd\/.htpasswd\r\n    <span class=\"nc\">AuthName<\/span> \"Please enter your ID <span class=\"ss\">and<\/span> password\"\r\n    <span class=\"nc\">AuthType<\/span> <span class=\"ss\">Basic<\/span>\r\n\r\n    <span class=\"c\"># \u3044\u305a\u308c\u304b\u306e\u6761\u4ef6\u3092\u6e80\u305f\u305b\u3070\u30a2\u30af\u30bb\u30b9\u53ef<\/span>\r\n    <span class=\"nc\">Require<\/span> <span class=\"ss\">env<\/span> healthcheck\r\n    <span class=\"nc\">Require<\/span> valid-user\r\n<span class=\"p\">&lt;\/<\/span><span class=\"nl\">RequireAny<\/span><span class=\"p\">&gt;\r\n<\/span>\r\n<span class=\"p\">&lt;<\/span><span class=\"nl\">Files<\/span><span class=\"sr\"> ~ \"^\\.(htaccess|htpasswd)$\"<\/span><span class=\"p\">&gt;\r\n<\/span>    <span class=\"nc\">Require<\/span> <span class=\"ss\">all<\/span> denied\r\n<span class=\"p\">&lt;\/<\/span><span class=\"nl\">Files<\/span><span class=\"p\">&gt;\r\n<\/span><\/code><\/pre>\n<p>Satisfy Any\u8868\u793a\u53ea\u8981\u6ee1\u8db3\u4efb\u4f55\u4e00\u4e2a\u6761\u4ef6\uff0c\u5c31\u53ef\u4ee5\u8bbf\u95ee\u3002<\/p>\n<p>\u5728\u4f7f\u7528Docker\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5c06AuthUserFile\u7684\u5b8c\u6574\u8def\u5f84\u6839\u636eDocker\u7684\u8def\u5f84\u8fdb\u884c\u8c03\u6574\uff0c\u800c\u4e0d\u662f\u670d\u52a1\u5668\u7684\u8def\u5f84\u3002<\/p>\n<h3>\u4f7f\u7528Windows\u670d\u52a1\u5668\u65f6\uff0c\u5c06Apache\u4e0eELB\u914d\u5408\u4f7f\u7528\uff08\u5728httpd.conf\u6587\u4ef6\u4e2d\u586b\u5199\uff09\u3002<\/h3>\n<p>\u8fd9\u662f\u4e00\u4e2a\u8bbe\u7f6e\u901a\u8fc7 healthcheck.html \u6587\u4ef6\u8fdb\u884c\u5065\u5eb7\u68c0\u67e5\u7684\u914d\u7f6e\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"c\"># Basic Auth\r\n<\/span>&lt;<span class=\"n\">Location<\/span> <span class=\"s2\">\"\/\"<\/span>&gt;\r\n    <span class=\"n\">AuthType<\/span> <span class=\"n\">Basic<\/span>\r\n    <span class=\"n\">AuthName<\/span> <span class=\"s2\">\"test basic auth\"<\/span>\r\n    <span class=\"n\">AuthUserFile<\/span> <span class=\"s2\">\"C:\\Apache24\\htpasswd\\.htpasswd\"<\/span>\r\n    <span class=\"n\">Require<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">user<\/span>\r\n\r\n    <span class=\"n\">SetEnvIf<\/span> <span class=\"n\">Request_URI<\/span> <span class=\"s2\">\"\/healthcheck.html\"<\/span> <span class=\"n\">healthcheck<\/span>\r\n\r\n   <span class=\"c\"># \u4ee5\u4e0b\u306e\u6761\u4ef6\u306b\u30de\u30c3\u30c1\u3059\u308b\u5834\u5408\u306fBasic\u8a8d\u8a3c\u306a\u3057\r\n<\/span>   &lt;<span class=\"n\">RequireAny<\/span>&gt;\r\n     <span class=\"n\">Require<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">user<\/span>\r\n     <span class=\"n\">Require<\/span> <span class=\"n\">env<\/span> <span class=\"n\">healthcheck<\/span>\r\n   &lt;\/<span class=\"n\">RequireAny<\/span>&gt;\r\n&lt;\/<span class=\"n\">Location<\/span>&gt;\r\n<\/code><\/pre>\n<h3>Apache + Windows\u670d\u52a1\u5668\uff08\u5728\u4f7f\u7528ELB\u65f6\uff0c\u5728httpd.conf\u4e2d\u5199\u5165\uff09\u2461<\/h3>\n<p>\u5982\u679c\u9700\u8981\u901a\u8fc7 healthcheck.html \u6587\u4ef6\u7684\u5065\u5eb7\u68c0\u67e5\uff0c\u5e76\u4e14\u4ec5\u8def\u7531\u7279\u5b9a\u7684\u5b50\u57df\u540d\uff0c\u5219\u9700\u8981\u8fdb\u884c\u65e0\u57fa\u672c\u8ba4\u8bc1\u7684\u8bbe\u7f6e\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"c\"># Basic Auth\r\n<\/span>&lt;<span class=\"n\">Location<\/span> <span class=\"s2\">\"\/\"<\/span>&gt;\r\n    <span class=\"n\">AuthType<\/span> <span class=\"n\">Basic<\/span>\r\n    <span class=\"n\">AuthName<\/span> <span class=\"s2\">\"test basic auth\"<\/span>\r\n    <span class=\"n\">AuthUserFile<\/span> <span class=\"s2\">\"C:\\Apache24\\htpasswd\\.htpasswd\"<\/span>\r\n    <span class=\"n\">Require<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">user<\/span>\r\n\r\n    <span class=\"n\">SetEnvIf<\/span> <span class=\"n\">Request_URI<\/span> <span class=\"s2\">\"\/healthcheck.html\"<\/span> <span class=\"n\">healthcheck<\/span>\r\n    <span class=\"n\">SetEnvIf<\/span> <span class=\"n\">Host<\/span> <span class=\"s2\">\"^do1.api\\.\"<\/span> <span class=\"n\">host_ok<\/span>\r\n\r\n   <span class=\"c\"># \u4ee5\u4e0b\u306e\u6761\u4ef6\u306b\u30de\u30c3\u30c1\u3059\u308b\u5834\u5408\u306fBasic\u8a8d\u8a3c\u306a\u3057\r\n<\/span>   &lt;<span class=\"n\">RequireAny<\/span>&gt;\r\n     <span class=\"n\">Require<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">user<\/span>\r\n     <span class=\"n\">Require<\/span> <span class=\"n\">env<\/span> <span class=\"n\">healthcheck<\/span>\r\n     <span class=\"n\">Require<\/span> <span class=\"n\">env<\/span> <span class=\"n\">host_ok<\/span>\r\n   &lt;\/<span class=\"n\">RequireAny<\/span>&gt;\r\n&lt;\/<span class=\"n\">Location<\/span>&gt;\r\n<\/code><\/pre>\n<h3>Apache\u4e0eWindows\u670d\u52a1\u5668\uff08\u5728\u4f7f\u7528ELB\u65f6\u9700\u5728httpd.conf\u4e2d\u586b\u5199\uff09.<\/h3>\n<p>\u9664\u4e86\u901a\u8fc7healthcheck.html\u6587\u4ef6\u8fdb\u884c\u5065\u5eb7\u68c0\u67e5\uff0c\u8fd8\u9700\u8981\u4ec5\u5c06\u7279\u5b9a\u7684\u5b50\u57df\u540d\u8fdb\u884c\u8def\u7531\uff0c\u4ee5\u53ca\u5728\u7279\u5b9a\u7684IP\u60c5\u51b5\u4e0b\uff0c\u8bbe\u7f6e\u4e3a\u65e0\u9700\u57fa\u672c\u8ba4\u8bc1\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"c\"># Basic Auth\r\n<\/span>&lt;<span class=\"n\">Location<\/span> <span class=\"s2\">\"\/\"<\/span>&gt;\r\n    <span class=\"n\">AuthType<\/span> <span class=\"n\">Basic<\/span>\r\n    <span class=\"n\">AuthName<\/span> <span class=\"s2\">\"test basic auth\"<\/span>\r\n    <span class=\"n\">AuthUserFile<\/span> <span class=\"s2\">\"C:\\Apache24\\htpasswd\\.htpasswd\"<\/span>\r\n    <span class=\"n\">Require<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">user<\/span>\r\n\r\n    <span class=\"n\">SetEnvIf<\/span> <span class=\"n\">REMOTE_ADDR<\/span> <span class=\"m\">222<\/span>.<span class=\"m\">222<\/span>.<span class=\"m\">222<\/span>.<span class=\"m\">222<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">ip<\/span>\r\n    <span class=\"n\">SetEnvIf<\/span> <span class=\"n\">Request_URI<\/span> <span class=\"s2\">\"\/healthcheck.html\"<\/span> <span class=\"n\">healthcheck<\/span>\r\n    <span class=\"n\">SetEnvIf<\/span> <span class=\"n\">Host<\/span> <span class=\"s2\">\"^do1.api\\.\"<\/span> <span class=\"n\">host_ok<\/span>\r\n\r\n   <span class=\"c\"># \u4ee5\u4e0b\u306e\u6761\u4ef6\u306b\u30de\u30c3\u30c1\u3059\u308b\u5834\u5408\u306fBasic\u8a8d\u8a3c\u306a\u3057\r\n<\/span>   &lt;<span class=\"n\">RequireAny<\/span>&gt;\r\n     <span class=\"n\">Require<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">user<\/span>\r\n     <span class=\"n\">Require<\/span> <span class=\"n\">env<\/span> <span class=\"n\">healthcheck<\/span>\r\n     <span class=\"n\">Require<\/span> <span class=\"n\">env<\/span> <span class=\"n\">host_ok<\/span>\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000<span class=\"n\">Require<\/span> <span class=\"n\">env<\/span> <span class=\"n\">valid<\/span>-<span class=\"n\">ip<\/span>\r\n   &lt;\/<span class=\"n\">RequireAny<\/span>&gt;\r\n&lt;\/<span class=\"n\">Location<\/span>&gt;\r\n<\/code><\/pre>\n<p>\u6587\u732e\u5217\u8868<\/p>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">apache\u306f\u2191\u3053\u3061\u3089\u306e\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3057\u307e\u3057\u305f<\/ul>\n<p>&nbsp;<\/p>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u5982\u4f55\u8bbe\u7f6eNginx\u7684\u57fa\u672c\u8ba4\u8bc1\u3002<br \/>\n\u665a\u4e0a\u597d\uff0c\u6211\u662fX-Forwarded-For\u8b66\u5bdf\u3002<br \/>\n\u5728Apache 2.4\u7248\u672c\u4e2d\uff0c\u5982\u4f55\u8bbe\u7f6eIP\u9650\u5236\u3002<br \/>\n\u5728Nginx\u4e2d\u4f7f\u7528\u57fa\u672c\u8ba4\u8bc1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148 \u6211\u6574\u7406\u4e86\u5173\u4e8eNginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u4ee5\u53caIP\u9650\u5236\uff08\u4e5f\u8003\u8651\u5230Elastic Load Balan [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-32776","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6574\u7406\u4e86Nginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cIP\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\u8003\u8651\u5230ELB\u7684\u5b58\u5728\u4e0e\u5426\uff09 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u6574\u7406\u4e86nginx\u548capache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cip\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6574\u7406\u4e86Nginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cIP\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\u8003\u8651\u5230ELB\u7684\u5b58\u5728\u4e0e\u5426\uff09\" \/>\n<meta property=\"og:description\" content=\"\u9996\u5148 \u6211\u6574\u7406\u4e86\u5173\u4e8eNginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u4ee5\u53caIP\u9650\u5236\uff08\u4e5f\u8003\u8651\u5230Elastic Load Balan [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u6574\u7406\u4e86nginx\u548capache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cip\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-31T21:15:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-04T11:16:33+00:00\" \/>\n<meta name=\"author\" content=\"\u65b0, \u97f5\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u65b0, \u97f5\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/\",\"name\":\"\u6574\u7406\u4e86Nginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cIP\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\u8003\u8651\u5230ELB\u7684\u5b58\u5728\u4e0e\u5426\uff09 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-03-31T21:15:40+00:00\",\"dateModified\":\"2024-05-04T11:16:33+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/4ba4019495123db3038fd0809e6959c9\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6574\u7406\u4e86Nginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cIP\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\u8003\u8651\u5230ELB\u7684\u5b58\u5728\u4e0e\u5426\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/4ba4019495123db3038fd0809e6959c9\",\"name\":\"\u65b0, \u97f5\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d484b6c6e4ae82e8a9efea989e1d2af46d9b6ef128101e63b18f559fca0ae627?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d484b6c6e4ae82e8a9efea989e1d2af46d9b6ef128101e63b18f559fca0ae627?s=96&d=mm&r=g\",\"caption\":\"\u65b0, \u97f5\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunxin\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u6574\u7406\u4e86Nginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cIP\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\u8003\u8651\u5230ELB\u7684\u5b58\u5728\u4e0e\u5426\uff09 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u6574\u7406\u4e86nginx\u548capache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cip\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\/","og_locale":"zh_CN","og_type":"article","og_title":"\u6574\u7406\u4e86Nginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cIP\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\u8003\u8651\u5230ELB\u7684\u5b58\u5728\u4e0e\u5426\uff09","og_description":"\u9996\u5148 \u6211\u6574\u7406\u4e86\u5173\u4e8eNginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u4ee5\u53caIP\u9650\u5236\uff08\u4e5f\u8003\u8651\u5230Elastic Load Balan [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u6574\u7406\u4e86nginx\u548capache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cip\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-03-31T21:15:40+00:00","article_modified_time":"2024-05-04T11:16:33+00:00","author":"\u65b0, \u97f5","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u65b0, \u97f5","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/","name":"\u6574\u7406\u4e86Nginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cIP\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\u8003\u8651\u5230ELB\u7684\u5b58\u5728\u4e0e\u5426\uff09 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-03-31T21:15:40+00:00","dateModified":"2024-05-04T11:16:33+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/4ba4019495123db3038fd0809e6959c9"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u6574\u7406\u4e86Nginx\u548cApache\u7684\u57fa\u672c\u8ba4\u8bc1\u548cIP\u9650\u5236\u7684\u5404\u79cd\u8bbe\u7f6e\u65b9\u6cd5\uff08\u8003\u8651\u5230ELB\u7684\u5b58\u5728\u4e0e\u5426\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/4ba4019495123db3038fd0809e6959c9","name":"\u65b0, \u97f5","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d484b6c6e4ae82e8a9efea989e1d2af46d9b6ef128101e63b18f559fca0ae627?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d484b6c6e4ae82e8a9efea989e1d2af46d9b6ef128101e63b18f559fca0ae627?s=96&d=mm&r=g","caption":"\u65b0, \u97f5"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunxin\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%95%b4%e7%90%86%e4%ba%86nginx%e5%92%8capache%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%ae%a4%e8%af%81%e5%92%8cip%e9%99%90%e5%88%b6%e7%9a%84%e5%90%84%e7%a7%8d%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95%ef%bc%88\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=32776"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32776\/revisions"}],"predecessor-version":[{"id":100180,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32776\/revisions\/100180"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=32776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=32776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=32776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}