{"id":192227,"date":"2020-06-06T09:42:33","date_gmt":"2020-06-06T01:42:33","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=192227"},"modified":"2020-08-26T06:39:34","modified_gmt":"2020-08-25T22:39:34","slug":"apache-virtual-hosts","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/apache-virtual-hosts.html","title":{"rendered":"\u5728CentOS 8\u4e0a\u5b89\u88c5\u4e0e\u914d\u7f6eApache\u865a\u62df\u4e3b\u673a"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nApache\u670d\u52a1\u5668\u662f\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u5305\u62ecUNIX\u548cWindows\u7b49\u5f00\u53d1\u548c\u7ef4\u62a4\u5f00\u6e90\u7684HTTP\u670d\u52a1\u5668\uff0capache\u63d0\u4f9b\u4e00\u4e2a\u5b89\u5168\u3001\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u7684\u670d\u52a1\u5668\uff0c\u63d0\u4f9b\u4e0e\u5f53\u524dHTTP\u6807\u51c6\u540c\u6b65\u7684HTTP\u670d\u52a1\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u5b9e\u9a8c\u73af\u5883<\/strong><\/div>\n

\u64cd\u4f5c\u7cfb\u7edf\uff1aCentos 8<\/p>\n

web\u5e94\u7528\uff1aapache<\/p>\n

\u5185\u7f51IP\uff1a192.168.3.21<\/p>\n

shell\u6267\u884c\uff1aroot<\/p>\n

\"\"<\/p>\n

\u4ee5root\u6216\u5177\u6709sudo\u6743\u9650\u7684\u7528\u6237\u8eab\u4efd\u767b\u5f55\u6267\u884c\u5982\u4e0b\u64cd\u4f5c\u3002<\/p>\n

\u5b89\u88c5httpd\u670d\u52a1<\/strong><\/span><\/div>\n
[root@linuxcool ~]# yum install httpd-devel.x86_64 httpd.x86_64 httpd-tools.x86_64\r\n<\/pre>\n
\u9a8c\u8bc1httpd\u662f\u5426\u5b89\u88c5\u6210\u529f<\/strong><\/span><\/div>\n
[root@linuxcool ~]# httpd -v\r\nServer version: Apache\/2.4.6 (CentOS)\r\nServer built:   Apr  2 2020 13:13:23\r\n<\/pre>\n
\u542f\u52a8httpd\u670d\u52a1<\/strong><\/span><\/div>\n
[root@linuxcool ~]# systemctl start httpd.service \r\n       \r\n[root@linuxcool ~]# systemctl status httpd.service \r\n\u25cf httpd.service - The Apache HTTP Server\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/httpd.service; disabled; vendor preset: disabled)\r\n   Active: active (running) since Fri 2020-05-22 12:23:03 CST; 25s ago\r\n     Docs: man:httpd(8)\r\n           man:apachectl(8)\r\n Main PID: 952 (httpd)\r\n   Status: \"Total requests: 0; Current requests\/sec: 0; Current traffic:   0 B\/sec\"\r\n    Tasks: 6\r\n   Memory: 3.6M\r\n   CGroup: \/system.slice\/httpd.service\r\n           \u251c\u2500952 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u2500953 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u2500954 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u2500955 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u2500956 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u2514\u2500957 \/usr\/sbin\/httpd -DFOREGROUND\r\n\r\nMay 22 12:23:03 linuxcool systemd[1]: Starting The Apache HTTP Server...\r\nMay 22 12:23:03 linuxcool httpd[952]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, u...message\r\nMay 22 12:23:03 linuxcool systemd[1]: Started The Apache HTTP Server.\r\nHint: Some lines were ellipsized, use -l to show in full.\r\n<\/pre>\n

apache\u5b89\u88c5\u6210\u529f\uff0c\u9ed8\u8ba4web\u76ee\u5f55\/var\/www\/<\/p>\n

\u6d4b\u8bd5<\/strong><\/span><\/div>\n
http:\/\/192.168.3.21\/\r\n<\/pre>\n

\"\"<\/p>\n

\u5b89\u88c5\u6210\u529f\uff01<\/p>\n

\u914d\u7f6eapache\u865a\u62df\u4e3b\u673a<\/strong><\/div>\n
\u521b\u5efa\u7f51\u7ad9\u76ee\u5f55<\/strong><\/span><\/div>\n
[root@linuxcool ~]# mkdir -p \/var\/www\/web1\r\n[root@linuxcool ~]# mkdir -p \/var\/www\/web2\r\n<\/pre>\n
web1\u6dfb\u52a0index.html<\/strong><\/span><\/div>\n
[root@linuxcool ~]# vim \/var\/www\/web1\/index.html\r\n<!DOCTYPE html>\r\n<html lang=\"en\" dir=\"ltr\">\r\n  <head>\r\n    <meta charset=\"utf-8\">\r\n    <title>Welcome to Web1<\/title>\r\n  <\/head>\r\n  <body>\r\n    <h1>Success! Web1 home page!<\/h1>\r\n  <\/body>\r\n<\/html>\r\n<\/pre>\n
web2\u6dfb\u52a0index.html<\/strong><\/span><\/div>\n
[root@linuxcool ~]# vim \/var\/www\/web2\/index.html\r\n<!DOCTYPE html>\r\n<html lang=\"en\" dir=\"ltr\">\r\n  <head>\r\n    <meta charset=\"utf-8\">\r\n    <title>Welcome to Web2<\/title>\r\n  <\/head>\r\n  <body>\r\n    <h1>Success! Web2 home page!<\/h1>\r\n  <\/body>\r\n<\/html>\r\n<\/pre>\n
\u6388\u6743web\u76ee\u5f55\u6743\u9650<\/strong><\/span><\/div>\n
[root@linuxcool ~]# chown -R apache: \/var\/www\/web1\/\r\n[root@linuxcool ~]# chown -R apache: \/var\/www\/web2\/\r\n<\/pre>\n
\u521b\u5efa\u865a\u62df\u4e3b\u673a\u6587\u4ef6<\/strong><\/span><\/div>\n

#web1<\/p>\n

[root@linuxcool ~]# vim \/etc\/httpd\/conf.d\/web1.conf\r\n<VirtualHost *:80>\r\nServerName web1.com\r\nServerAlias www.web1.com\r\nServerAdmin webmaster@example.com\r\nDocumentRoot \/var\/www\/web1\r\n\r\n<Directory \/var\/www\/web1\/>\r\nOptions -Indexes +FollowSymLinks\r\nAllowOverride All\r\n<\/Directory>\r\n\r\nErrorLog \/var\/log\/httpd\/example.com-error.log\r\nCustomLog \/var\/log\/httpd\/example.com-access.log combined\r\n<\/VirtualHost>\r\n<\/pre>\n

#web2<\/p>\n

[root@linuxcool ~]# vim \/etc\/httpd\/conf.d\/web2.conf\r\n<VirtualHost *:80>\r\nServerName web2.com\r\nServerAlias www.web2.com\r\nServerAdmin webmaster@example.com\r\nDocumentRoot \/var\/www\/web2\r\n\r\n<Directory \/var\/www\/web2\/>\r\nOptions -Indexes +FollowSymLinks\r\nAllowOverride All\r\n<\/Directory>\r\n\r\nErrorLog \/var\/log\/httpd\/example.com-error.log\r\nCustomLog \/var\/log\/httpd\/example.com-access.log combined\r\n<\/VirtualHost>\r\n<\/pre>\n
\u91cd\u542fhttpd\u670d\u52a1<\/strong><\/span><\/div>\n
[root@linuxcool ~]# systemctl restart httpd.service\r\n<\/pre>\n
\u9a8c\u8bc1httpd\u865a\u62df\u4e3b\u673a\u7ed3\u679c<\/strong><\/span><\/div>\n

http:\/\/www.web1.com<\/a><\/p>\n

\"\"<\/p>\n

http:\/\/www.web2.com<\/a><\/p>\n

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

\u64cd\u4f5c\u7cfb\u7edf\uff1aCentos 8 web\u5e94\u7528\uff1aapache \u5185\u7f51IP\uff1a192.168.3.21 shell\u6267\u884c\uff1aro […]<\/p>\n","protected":false},"author":1479,"featured_media":192228,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-192227","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/192227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=192227"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/192227\/revisions"}],"predecessor-version":[{"id":199511,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/192227\/revisions\/199511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/192228"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=192227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=192227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=192227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}