{"id":32743,"date":"2022-09-07T15:20:23","date_gmt":"2023-06-12T18:22:31","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/"},"modified":"2024-01-15T07:28:14","modified_gmt":"2024-01-14T23:28:14","slug":"nginx%e5%92%8capache","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/","title":{"rendered":"Nginx\u548cApache"},"content":{"rendered":"<h3>\u524d\u63d0<\/h3>\n<p>\u5728\u901a\u5e38\u4f7f\u7528Apache\u4f5c\u4e3aWEB\u670d\u52a1\u5668\u7684\u73af\u5883\u4e2d\uff0c<br \/>\n\u5c06Nginx\u4f5c\u4e3a\u4ee3\u7406\u670d\u52a1\u5668\u653e\u7f6e\u5728\u524d\u7aef\uff0c<br \/>\n\u5c06Apache\u4f5c\u4e3a\u540e\u7aef\uff0c<br \/>\n\u4ee5\u52a0\u5feb\u5904\u7406\u901f\u5ea6\u3002<\/p>\n<p>\u6211\u7684\u73af\u5883\u662fCentOS 6.4\uff0cApache 2.2.15\u548cNginx 1.0.15\u3002<\/p>\n<p>\u5047\u8bbeApache\u5df2\u7ecf\u5b89\u88c5\u597d\u4e86\u3002<\/p>\n<h3>mod_rpaf is a vital module used in Apache web server to replace the values of REMOTE_ADDR variable with the values of X-Forwarded-For header in order to obtain the original client IP address.<\/h3>\n<p>\u5b89\u88c5Apache\u6a21\u5757mod_rpaf\u3002\u5173\u4e8emod_rpaf\uff0c\u8fd9\u91cc\u53ef\u80fd\u4f1a\u6709\u53c2\u8003\uff1a<br \/>\nhttp:\/\/heartbeats.jp\/hbblog\/2012\/03\/mod-rpaf.html<\/p>\n<p>\u30fc\u30fc\u30fc\u30fc\u30fc\u30fc\u30fc\u30fc\u30fc\u30fc<br \/>\nsudo yum install -y httpd-devel<\/p>\n<p>\u5207\u6362\u5230 \/usr\/local\/src\/ \u76ee\u5f55\u4e0b<br \/>\n\u4f7f\u7528 sudo \u547d\u4ee4\u4e0b\u8f7d http:\/\/stderr.net\/apache\/rpaf\/download\/mod_rpaf-0.6.tar.gz<br \/>\n\u4f7f\u7528 sudo \u547d\u4ee4\u89e3\u538b mod_rpaf-0.6.tar.gz \u6587\u4ef6<br \/>\n\u5207\u6362\u5230 mod_rpaf-0.6 \u76ee\u5f55\u4e0b<\/p>\n<p>\u8bf7\u7f16\u8f91Makefile\u7684\u7b2c\u56db\u884c\u9644\u8fd1\u3002<br \/>\n\uff03APXS2=$(shell which apxs2) \u2190\u5c06\u5176\u6ce8\u91ca\u6389<br \/>\nAPXS2=\/usr\/sbin\/apxs \u2190\u6dfb\u52a0<\/p>\n<p>sudo make rpaf-2.0<br \/>\nsudo make install-2.0<\/p>\n<p>\u7528\u4e2d\u6587\u672c\u5730\u5316\u5730\u6539\u5199\u4e3a\uff1a<br \/>\nsudo make rpaf-2.0<br \/>\nsudo make install-2.0<\/p>\n<p>\u8bf7\u5c06\/usr\/lib64\/httpd\/modules\/mod_rpaf-2.0.so\u7684\u6743\u9650\u6539\u4e3a755\u3002<\/p>\n<h3>Nginx\u5c31\u53ef\u4ee5\u3002<\/h3>\n<p>\u5b89\u88c5Nginx\uff0c\u5e76\u8fdb\u884c\u4ee3\u7406\u670d\u52a1\u5668\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u4f7f\u7528 sudo \u547d\u4ee4\u5b89\u88c5 nginx\uff0c\u547d\u4ee4\u4e3a yum install -y nginx\u3002<\/p>\n<p>\u67e5\u8be2\u7248\u672c\u786e\u8ba4<br \/>\nyum\u5217\u8868\u5df2\u5b89\u88c5 | grep nginx<br \/>\nnginx.x86_64 1.0.15-5.el6 @epel<\/p>\n<p>\u521b\u5efa\u7528\u4e8e\u4ee3\u7406\u7684conf\u6587\u4ef6\u3002<br \/>\n\u4f7f\u7528sudo vi\u547d\u4ee4\u7f16\u8f91\/etc\/nginx\/conf.d\/proxy.conf\u6587\u4ef6\u3002<br \/>\n\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<br \/>\nproxy_set_header Host $http_host;<br \/>\nproxy_set_header X-Real-IP $remote_addr;<br \/>\nproxy_set_header X-Forwarded-Proto $scheme;<br \/>\nproxy_set_header X-Forwarded-Host $http_host;<br \/>\nproxy_set_header X-Forwarded-Server $host;<br \/>\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<\/p>\n<p>\u8fdb\u5165\/etc\/nginx\/\u76ee\u5f55<br \/>\nsudo\u521b\u5efasites-available\u6587\u4ef6\u5939<br \/>\nsudo\u521b\u5efasites-enabled\u6587\u4ef6\u5939<\/p>\n<p>\u5728nginx.conf\u7684http\u90e8\u5206\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4e00\u884c\uff1a<br \/>\n\u5305\u542b\/ etc \/ nginx \/ sites-enabled \/ *;<\/p>\n<p>\u521b\u5efa\/etc\/nginx\/sites-available\/ {\u9002\u5f53\u7684\u57df\u540d} \u5e76\u8bbe\u7f6e\u865a\u62df\u4e3b\u673a\uff0c\u5982\u4e0b\u6240\u793a\uff1a<br \/>\nserver {<br \/>\nlisten 80;<br \/>\nserver_name .{\u57df\u540d};<br \/>\n\uff03\u5728\u57df\u540d\u524d\u9762\u52a0\u4e0a\u70b9\u662f\u4e3a\u4e86\u5339\u914d\u6240\u6709\u5b50\u57df\u540d\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5bf9\u7ed9\u5b9a\u5185\u5bb9\u7684\u4e2d\u6587\u91ca\u4e49\uff1a<\/p>\n<p>\/\/ \u540e\u7aef\u670d\u52a1\u5668\u7684\u7aef\u53e3\u8bbe\u7f6e\u4e3a8000<br \/>\nlocation \/ {<br \/>\n\u4ee3\u7406\u8f6c\u53d1 http:\/\/localhost:8000;<br \/>\n\u4ee3\u7406\u91cd\u5b9a\u5411\u9ed8\u8ba4;<br \/>\n\u4e2d\u65ad;<br \/>\n}<br \/>\n}<\/p>\n<p>\u521b\u5efa\u7b26\u53f7\u94fe\u63a5<br \/>\ncd \/etc\/nginx\/sites-enabled\/<br \/>\nsudo ln -s ..\/sites-available\/{\u9002\u5f53\u7684\u57df\u540d\u6216\u540d\u79f0}<\/p>\n<h3>\u963f\u5e15\u5947<\/h3>\n<p>\u8fdb\u884c\u7aef\u53e3\u66f4\u6539\u548c\u52a0\u8f7dmod_rpaf\u7684\u914d\u7f6e\u8bbe\u7f6e\u3002<\/p>\n<p>\u8bf7\u5c06\u7aef\u53e3\u53f7\u6539\u4e3a8000\uff0c\u4ee5\u4e0b\u4e3ahttpd.conf\u6587\u4ef6\u7684\u8bbe\u7f6e\u90e8\u5206\uff1a<br \/>\n\u9996\u5148\uff0c\u8bf7\u5c06Listen 80\u548cNameVirtualHost *:80\u7b49\u5904\u7684\u7aef\u53e3\u53f7\u6539\u4e3a8000\u3002<\/p>\n<p>\u7136\u540e\uff0c\u5728VirtualHost\u58f0\u660e\u7684\u524d\u9762\u5199\u4e0b\u4ee5\u4e0b\u5185\u5bb9\u3002<\/p>\n<p>\u53cd\u5411\u4ee3\u7406<br \/>\n\u52a0\u8f7d\u6a21\u5757 rpaf_module \/usr\/lib64\/httpd\/modules\/mod_rpaf-2.0.so<br \/>\n\u542f\u7528RPAF<br \/>\n\u8bbe\u7f6eRPAF\u4e3b\u673a\u540d<br \/>\nRPAF\u4ee3\u7406IP\u5730\u5740 127.0.0.1 10.0.0.1<br \/>\nRPAF\u5934\u90e8 X-Forwarded-For<\/p>\n<p>\u8bf7\u91cd\u65b0\u542f\u52a8Apache\u670d\u52a1\u5668\uff0c\u5982\u679c\u65e0\u6cd5\u901a\u8fc7\u5e38\u89c4URL\u8bbf\u95ee\uff0c\u8bf7\u786e\u4fdd\u53ef\u4ee5\u901a\u8fc7domain:8000\u8bbf\u95ee\u3002<\/p>\n<h3>\u6700\u540e<\/h3>\n<p>\u5982\u679c\u6210\u529f\u542f\u52a8Nginx\u5e76\u80fd\u591f\u8bbf\u95ee\u6307\u5b9a\u7684\u57df\u540d\uff0c\u90a3\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>\u7531\u4e8e\u53ef\u4ee5\u901a\u8fc7\u5168\u5c40\u7684\u57df\u540d:8000\u8bbf\u95ee\uff0c\u56e0\u6b64\u9700\u8981\u5728Apache\u7684httpd.conf\u4e2d\u8fdb\u884c\u66f4\u6539\uff0c\u53ea\u63a5\u53d7\u6765\u81eaNginx\uff08\u672c\u5730\u4e3b\u673a\uff09\u7684\u8bf7\u6c42\u3002<\/p>\n<p>\u8fd9\u5c31\u5b8c\u6210\u4e86\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u63d0 \u5728\u901a\u5e38\u4f7f\u7528Apache\u4f5c\u4e3aWEB\u670d\u52a1\u5668\u7684\u73af\u5883\u4e2d\uff0c \u5c06Nginx\u4f5c\u4e3a\u4ee3\u7406\u670d\u52a1\u5668\u653e\u7f6e\u5728\u524d\u7aef\uff0c \u5c06Apache [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-32743","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>Nginx\u548cApache - 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\/nginx\u548capache\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Nginx\u548cApache\" \/>\n<meta property=\"og:description\" content=\"\u524d\u63d0 \u5728\u901a\u5e38\u4f7f\u7528Apache\u4f5c\u4e3aWEB\u670d\u52a1\u5668\u7684\u73af\u5883\u4e2d\uff0c \u5c06Nginx\u4f5c\u4e3a\u4ee3\u7406\u670d\u52a1\u5668\u653e\u7f6e\u5728\u524d\u7aef\uff0c \u5c06Apache [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/nginx\u548capache\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-12T18:22:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-14T23:28:14+00:00\" \/>\n<meta name=\"author\" content=\"\u97f5, \u79d1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u97f5, \u79d1\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \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\/nginx%e5%92%8capache\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/\",\"name\":\"Nginx\u548cApache - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-06-12T18:22:31+00:00\",\"dateModified\":\"2024-01-14T23:28:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Nginx\u548cApache\"}]},{\"@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\/6530331a63adef3b3443a1fab53a0e6e\",\"name\":\"\u97f5, \u79d1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"caption\":\"\u97f5, \u79d1\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Nginx\u548cApache - 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\/nginx\u548capache\/","og_locale":"zh_CN","og_type":"article","og_title":"Nginx\u548cApache","og_description":"\u524d\u63d0 \u5728\u901a\u5e38\u4f7f\u7528Apache\u4f5c\u4e3aWEB\u670d\u52a1\u5668\u7684\u73af\u5883\u4e2d\uff0c \u5c06Nginx\u4f5c\u4e3a\u4ee3\u7406\u670d\u52a1\u5668\u653e\u7f6e\u5728\u524d\u7aef\uff0c \u5c06Apache [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/nginx\u548capache\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-06-12T18:22:31+00:00","article_modified_time":"2024-01-14T23:28:14+00:00","author":"\u97f5, \u79d1","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u97f5, \u79d1","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/","name":"Nginx\u548cApache - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-06-12T18:22:31+00:00","dateModified":"2024-01-14T23:28:14+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"Nginx\u548cApache"}]},{"@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\/6530331a63adef3b3443a1fab53a0e6e","name":"\u97f5, \u79d1","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","caption":"\u97f5, \u79d1"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/nginx%e5%92%8capache\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32743","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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=32743"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32743\/revisions"}],"predecessor-version":[{"id":57367,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32743\/revisions\/57367"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=32743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=32743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=32743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}