{"id":1699,"date":"2017-09-24T17:51:56","date_gmt":"2017-09-24T09:51:56","guid":{"rendered":"https:\/\/zoco.me\/?p=10"},"modified":"2017-09-24T17:51:56","modified_gmt":"2017-09-24T09:51:56","slug":"centos-7-config-apache-httpd","status":"publish","type":"post","link":"https:\/\/cloudbool.com\/archive\/centos-7-config-apache-httpd.html","title":{"rendered":"CentOS 7 \u7cfb\u7edf\u914d\u7f6eApache"},"content":{"rendered":"<p>\u73b0\u5728\u516c\u53f8\u7684\u9879\u76ee\u7531\u4e8e\u4e00\u76f4\u662f\u4e00\u4e2a\u5916\u5305\u56e2\u961f\u5728\u7ef4\u62a4\uff0c\u4e00\u76f4\u8fd0\u884c\u5728Windows Server\u4e0a\uff0c\u6211\u63a5\u624b\u4e4b\u540e\u4ece\u957f\u8fdc\u8003\u8651\u4ee5\u53ca\u719f\u7ec3\u53ca\u5b89\u5168\u3001\u6027\u80fd\u7b49\u65b9\u9762\u8003\u8651\uff0c\u6211\u6700\u7ec8\u51b3\u5b9a\u6362\u6210Linux\uff0c\u800c\u7531\u4e8e\u8fd0\u884c\u7684\u662f\u516c\u53f8\u7684\u6b63\u5f0f\u9879\u76ee\uff0c\u6beb\u65e0\u7591\u95ee\u9009\u62e9\u4e86CentOS\uff0c\u81f3\u4e8e\u7248\u672c\uff0c\u6211\u9009\u62e9\u4e86\u6700\u65b0\u7684CentOS7\u3002\u800c\u670d\u52a1\u5668\u672c\u6253\u7b97\u662f\u7528\u6d41\u884c\u7684Nginx\u7684\uff0c\u4f46\u662f\u51e0\u4e2aCGI\u53c2\u6570\u59cb\u7ec8\u65e0\u6cd5\u914d\u7f6e\u597d\uff0c\u51fa\u4e8e\u7a33\u5b9a\u6027\u8003\u8651\uff0c\u6700\u540e\u9009\u62e9\u4e86Apache\u3002<\/p>\n<p><!--more--><\/p>\n<h3>\u5b89\u88c5\u57fa\u672c\u8f6f\u4ef6\u5305<\/h3>\n<p>\u7531\u4e8eCentOS 7 \u81ea\u5e26\u7684PHP\u7248\u672c\u624d5.4\uff0c\u4e0d\u80fd\u6ee1\u8db3\u6211\u4eec\u5f00\u53d1\u7684\u7a0b\u5e8f\u7684\u8981\u6c42\uff0c\u672c\u7740\u80fd\u5305\u7ba1\u7406\u5668\u5b89\u88c5\u5c31\u4e0d\u7f16\u8bd1\u5b89\u88c5\u7684\u539f\u5219\uff0c\u9009\u62e9\u4e86webstatic\u8fd9\u4e2a\u6e90\u7684\u5305\uff0c\u66f4\u65b0\u7cfb\u7edf:<\/p>\n<blockquote><p>\n  yum update\n<\/p><\/blockquote>\n<p>\u5b89\u88c5EPEL\u6e90\uff1a<\/p>\n<blockquote><p>\n  yum install epel-release\n<\/p><\/blockquote>\n<p>\u5b89\u88c5webstatic\u6e90\uff1a<\/p>\n<blockquote><p>\n  rpm -Uvh https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm\n<\/p><\/blockquote>\n<p>\u5b89\u88c5Apache\u3001\u5b89\u88c5PHP\u53caMariadb\u6570\u636e\u5e93\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>\n  yum install httpd php56w php56w-mysql php56w-pdo php56w-gd php56w-mcrypt php56w-mbstring php56w-json php56w-xml php56w-openssl mariadb-server -y\n<\/p><\/blockquote>\n<p>\u5bf9\uff0c\u4f60\u6ca1\u770b\u9519\uff0cCentOS\u4e0b\u7684Apache\u5728\u5305\u7ba1\u7406\u5668\u4e2d\u7684\u540d\u5b57\u5c31\u662fhttpd\u3002\u8fd9\u6837\u5c31\u5b89\u88c5\u597d\u4e86\u5404\u4e2a\u6240\u9700\u8981\u7684\u7ec4\u4ef6\uff0c\u63a5\u4e0b\u6765\u5c31\u662f\u914d\u7f6e\u4e86\u3002<\/p>\n<h3>Apache\u57fa\u672c\u914d\u7f6e<\/h3>\n<p>\u7528 <code>yum<\/code> \u5b89\u88c5\u7684apache\uff0c\u914d\u7f6e\u6587\u4ef6\u5728 <code>\/etc\/httpd\/<\/code> \uff0c\u6211\u4eec\u9700\u8981\u6539\u7684\u5404\u4e2a\u914d\u7f6e\u6587\u4ef6\u90fd\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u9762\u3002<\/p>\n<p>\u9996\u5148\uff0c\u66f4\u6539<code>\/etc\/httpd\/conf\/httpd.conf<\/code>\u4e2d\u7684<code>ServerName<\/code>\u5b57\u6bb5\uff0c\u5426\u5219\u4f1a\u63d0\u793a<code>AH00558<\/code>\u5b57\u6bb5\uff1a<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-null\">[root@localhost ~]# httpd -t\nAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message\nSyntax OK\n<\/code><\/pre>\n<p>\u63a5\u7740\uff0c\u5728<code>\/etc\/httpd\/conf.d\/<\/code>\u4e0b\u9762\u65b0\u5efa\u4e00\u4e2a<code>example.conf<\/code>\u6587\u4ef6\uff0c\u8fd9\u4e2a\u5c31\u662f\u6211\u4eec\u9700\u8981\u7684\u865a\u62df\u4e3b\u673a\u914d\u7f6e\u6587\u4ef6\uff0c\u5982\u679c\u53ea\u662f\u60f3\u8981HTTP\u670d\u52a1\uff0c\u590d\u5236\u4e0b\u9762\u8fd9\u6bb5\u5e76\u8fdb\u884c\u76f8\u5e94\u4fee\u6539\u5373\u53ef\uff1a<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-apache\">&lt;VirtualHost *:80&gt;\nServerName www.example.com\nDocumentRoot \/var\/www\/example\/\nServerAlias example\nErrorLog \/var\/log\/httpd\/example.error.log\nCustomLog \/var\/log\/httpd\/example.log combined\n&lt;Directory \/var\/www\/example&gt;\n        Options Indexes FollowSymLinks MultiViews\n        AllowOverride FileInfo Options\n        Order allow,deny\n        allow from all\n&lt;\/Directory&gt;\nHeader unset X-Powered-By\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>\n<p>\u914d\u7f6e\u5b8c\u6210\u4e4b\u540e\uff0c\u7528apache\u81ea\u5e26\u7684\u5de5\u5177\u68c0\u67e5\u662f\u5426\u6709\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<h3>\u914d\u7f6eApache\u63d0\u4f9bHTTPS\u670d\u52a1<\/h3>\n<p>\u4f46\u662f\u7531\u4e8e\u73b0\u5728\u7684\u6f6e\u6d41\u662f\u63d0\u4f9bHTTPS\u670d\u52a1\uff0c\u6211\u4eec\u8fd9\u4e2a\u9879\u76ee\u4e5f\u7ed9App\u7aef\u63d0\u4f9b\u6570\u636e\u63a5\u53e3\u670d\u52a1\uff0c\u6309\u7167\u82f9\u679c\u7684\u8981\u6c42\u4ee5\u53ca\u5904\u4e8e\u5b89\u5168\u6027\u8003\u8651\uff0c\u786e\u5b9e\u6709\u5fc5\u8981\u4e0aHTTPS\u670d\u52a1\uff0c\u4f46\u662f\u8003\u8651\u5230\u5b9e\u9645\u4e1a\u52a1\u60c5\u51b5\uff0c\u6211\u4eec\u73b0\u9636\u6bb5\u4e0d\u6253\u7b97\u5f3a\u5236\u8df3\u8f6c\u5230HTTPS\u8bbf\u95ee\uff0c\u4e8e\u662f\u91c7\u7528\u7684\u662fHTTP\u548cHTTPS\u90fd\u53ef\u8bbf\u95ee\u7b56\u7565\uff0c\u8fd9\u5c31\u8981\u6c42\u8981\u51c6\u5907\u4e00\u4efdSSL\u8bc1\u4e66\u4e86\uff0c\u7533\u8bf7\u8bc1\u4e66\u8fd9\u4e00\u6b65\u6309\u4e0b\u4e0d\u8868\uff0c\u5f88\u591a\u9014\u5f84\u90fd\u53ef\u4ee5\u7533\u8bf7\uff0c\u6211\u8fd9\u91cc\u53ea\u8bb0\u5f55\u4e0b\u914d\u7f6e\u6b65\u9aa4\u3002<\/p>\n<p>\u8981\u4f7f\u7528<code>yum<\/code>\u5305\u7ba1\u7406\u5668\u5b89\u88c5\u7684Apache\u652f\u6301SSL\uff0c\u8fd8\u9700\u8981\u5b89\u88c5\u4e00\u4e2aApache\u6a21\u5757\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>\n  yum install mod_ssl\n<\/p><\/blockquote>\n<p>\u7136\u540e\u662f\u589e\u52a0\u5bf9\u5e94\u7684SSL\u914d\u7f6e\uff0c\u5728\u4e0a\u9762\u90a3\u4e2a\u914d\u7f6e\u6587\u4ef6\u672b\u5c3e\u589e\u52a0\u6216\u8005\u65b0\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u90fd\u884c\uff0c\u76f8\u5e94\u914d\u7f6e\uff1a<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-null\">&lt;VirtualHost *:443&gt;\nServerName https:\/\/www.example.com\nDocumentRoot \/var\/www\/example\/\nServerAlias example\nErrorLog \/var\/log\/httpd\/example.error.log\nCustomLog \/var\/log\/httpd\/example.log combined\n&lt;Directory \/var\/www\/example&gt;\n        Options Indexes FollowSymLinks MultiViews\n        AllowOverride FileInfo Options\n        Order allow,deny\n        allow from all\n&lt;\/Directory&gt;\nSSLEngine on\nSSLCertificateFile \/var\/www\/example-ssl\/xxx.pem\nSSLCertificateKeyFile \/var\/www\/example-ssl\/xxx.key\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>\n<p>\u590d\u5236\uff0c\u66f4\u6539\u5bf9\u5e94\u7684\u9879\u5373\u53ef\u3002<\/p>\n<p>\u7136\u540e\u518d\u6b21\u68c0\u67e5\u4e00\u4e0b\u8bed\u6cd5\u662f\u5426\u6709\u8bef\uff1a<\/p>\n<blockquote><p>\n  httpd -t\n<\/p><\/blockquote>\n<p>\u5982\u679c\u6ca1\u95ee\u9898\uff0c\u53ef\u4ee5\u91cd\u542f<code>httpd<\/code>\u670d\u52a1\uff1a<\/p>\n<blockquote><p>\n  systemctl restart httpd\n<\/p><\/blockquote>\n<h3>\u989d\u5916\u914d\u7f6e<\/h3>\n<p>\u4e0a\u9762\u6709\u4e2a\u914d\u7f6e\u9879\u6211\u8fd9\u91cc\u8bb0\u5f55\u4e00\u4e0b\uff0c<code>Header unset X-Powered-By<\/code>\u8fd9\u4e00\u884c\u662f\u8ba9<code>Apache<\/code>\u9690\u85cf\u5bf9\u5e94\u7684<code>http header<\/code>\uff0c\u5904\u4e8e\u5b89\u5168\u8003\u8651\u4e0d\u5141\u8bb8\u540e\u7aef\u66b4\u9732\u592a\u591a\u4fe1\u606f\u3002<\/p>\n<p>\u540c\u6837\u9700\u8981\u9690\u85cf\u7684\u8fd8\u6709Apache\u7684\u7248\u672c\u53f7\u4ee5\u53ca\u64cd\u4f5c\u7cfb\u7edf\u4fe1\u606f\uff0c\u5728<code>\/etc\/httpd\/conf\/httpd.conf<\/code>\u6587\u4ef6\u672b\u5c3e\u589e\u52a0\u4e0b\u9762\u4e24\u884c\uff1a<\/p>\n<blockquote><p>\n  ServerTokens Prod<br \/>\n  ServerSignature Off\n<\/p><\/blockquote>\n<p>\u6700\u540e\u518d\u68c0\u67e5\u4e00\u4e0b\u662f\u5426\u6709\u8bed\u6cd5\u9519\u8bef\uff0c\u5982\u679c\u4e00\u5207\u6b63\u5e38\u5219\u53ef\u4ee5\u91cd\u542fApache\u670d\u52a1\u6216\u8005\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u7531\u4e8eApache\u662f\u4ee5apache\u7528\u6237\u7ec4\u4e0b\u7684apache\u7528\u6237\u8fd0\u884c\u7684\uff0c\u6240\u4ee5\uff0c\u5bf9\u5e94\u7684\u7f51\u7ad9\u76ee\u5f55\u6587\u4ef6\u9700\u8981\u7ed9\u4e88\u5bf9\u5e94\u7684\u6743\u9650\u624d\u80fd\u4f7f\u7f51\u7ad9\u6b63\u5e38\u8fd0\u884c\uff1a<\/p>\n<blockquote><p>\n  chown -R apache.apache \/var\/www\/example\n<\/p><\/blockquote>\n<p>\u4e0a\u9762\u7684\u6587\u4ef6\u8def\u5f84\u6539\u6210\u5bf9\u5e94\u7684\u7f51\u7ad9\u6587\u4ef6\u8def\u5f84\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73b0\u5728\u516c\u53f8\u7684\u9879\u76ee\u7531\u4e8e\u4e00\u76f4\u662f\u4e00\u4e2a\u5916\u5305\u56e2\u961f\u5728\u7ef4\u62a4\uff0c\u4e00\u76f4\u8fd0\u884c\u5728Windows Server\u4e0a\uff0c\u6211\u63a5\u624b\u4e4b\u540e\u4ece\u957f\u8fdc\u8003\u8651\u4ee5\u53ca &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/cloudbool.com\/archive\/centos-7-config-apache-httpd.html\"> <span class=\"screen-reader-text\">CentOS 7 \u7cfb\u7edf\u914d\u7f6eApache<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[8],"tags":[15,17],"class_list":["post-1699","post","type-post","status-publish","format-standard","hentry","category-tech","tag-apache","tag-centos"],"_links":{"self":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/1699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/comments?post=1699"}],"version-history":[{"count":0,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/1699\/revisions"}],"wp:attachment":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/media?parent=1699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/categories?post=1699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/tags?post=1699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}