{"id":857,"date":"2019-11-07T15:36:06","date_gmt":"2019-11-07T06:36:06","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=857"},"modified":"2019-11-07T15:36:06","modified_gmt":"2019-11-07T06:36:06","slug":"ubuntu-1804-apache2-vhost-ssl-basic-auth","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2019\/11\/07\/ubuntu-1804-apache2-vhost-ssl-basic-auth\/","title":{"rendered":"Ubuntu18.04\u3067Apache2\/vhost\/SSL\u5316\/BASIC\u8a8d\u8a3c"},"content":{"rendered":"<p>\u305f\u307e\u306b\u3084\u308b\u306e\u3067\u30e1\u30e2\u3002<\/p>\n<p>Ubuntu18.04\u3060\u3051\u3069GCP\u306eComputeEngine\u3067\u3084\u308b\u306e\u3067ufw\u306f\u4f7f\u308f\u306a\u3044\u3002<\/p>\n<p>Firewall\u8a2d\u5b9a\u306e [Allow HTTP\/HTTPS traffic] \u3092ON\u306b\u3057\u3068\u304f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u5148\u306bDNS\u306bA\u30ec\u30b3\u30fc\u30c9\u767b\u9332\u3057\u3066\u304a\u304f\u3002<\/p>\n<h3>\u304a\u307e\u3058\u306a\u3044<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo apt update -y; sudo apt upgrade -y\n<\/pre>\n<h3>Apache2\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo apt install apache2 -y\n<\/pre>\n<p>\u30b5\u30fc\u30d0\u30fc\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u96a0\u3057\u305f\u3044\u306e\u3067ServerSignature\u3092\u7121\u52b9\u306b\u3059\u308b\u3002<br \/>\n\/etc\/apache2\/apache2.conf \u306b\u4e0b\u8a18\u3092\u8ffd\u8a18\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nServerSignature Off\nServerTokens Prod\n<\/pre>\n<h3>VirtualHost\u8a2d\u5b9a<\/h3>\n<p>\u4ee5\u4e0bwww2\u306f\u9069\u5b9c\u66f8\u304d\u63db\u3048\u308b\u3002<\/p>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u7528\u610f\u3059\u308b\u3002<br \/>\n\u305d\u3057\u3066sudo\u3057\u306a\u304f\u3066\u3082\u64cd\u4f5c\u3067\u304d\u308b\u3088\u3046\u306b\u30aa\u30fc\u30ca\u30fc\u3092\u81ea\u5206\u306b\u3059\u308b\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncd \/var\/www\nmkdir www2\nsudo chown ${USER}:${USER} www2\nsudo chmod 755 www2\n<\/pre>\n<p>conf\u4f5c\u308b\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncd  \/etc\/apache2\/sites-available\nsudo cp 000-default.conf www2.conf\n<\/pre>\n<p>\/etc\/apache2\/sites-available\/www2.conf\u306bvirtual host\u8a2d\u5b9a\u3092\u8ffd\u8a18\u3059\u308b\u3002<br \/>\nServerName\u306fDNS\u306bA\u30ec\u30b3\u30fc\u30c9\u767b\u9332\u3057\u305fFQDN\u306b\u3059\u308b\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n&lt;VirtualHost *:80&gt;\n  ServerAdmin root@localhost\n  ServerName www2.kwonline.org\n  DocumentRoot \/var\/www\/www2\n  ErrorLog ${APACHE_LOG_DIR}\/error.log\n  CustomLog ${APACHE_LOG_DIR}\/access.log combined\n&lt;\/VirtualHost&gt;\n<\/pre>\n<p>conf\u5207\u308a\u66ff\u3048\u3066Apache\u518d\u8d77\u52d5\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo a2ensite www2.conf\nsudo a2dissite 000-default.conf\nsudo systemctl restart apache2\n<\/pre>\n<h3>SSL\u5316<\/h3>\n<p>LetsEncrypt\u306ecertbot\u3092\u4f7f\u3046<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo add-apt-repository ppa:certbot\/certbot\n<\/pre>\n<p>\u78ba\u8a8d\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u51fa\u308b\u306e\u3067[Enter]\u30ad\u30fc\u3092\u62bc\u3059\u3002<br \/>\n\u4ee5\u4e0bwww2\u306eFQDN\u306f\u9069\u5b9c\u66f8\u304d\u63db\u3048\u308b<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo apt install python-certbot-apache -y\nsudo certbot --apache -d www2.kwonline.org\n<\/pre>\n<p>\u30e1\u30a2\u30c9\u3084HTTP\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306b\u3064\u3044\u3066\u8cea\u554f\u3055\u308c\u308b\u306e\u3067\u9069\u5b9c\u7b54\u3048\u308b\u3002<\/p>\n<h3>BASIC\u8a8d\u8a3c<\/h3>\n<p>htpasswd\u30b3\u30de\u30f3\u30c9\u306e\u521d\u56de\u5b9f\u884c\u6642\u306e\u307f[-c\u30aa\u30d7\u30b7\u30e7\u30f3]\u3092\u4ed8\u3051\u308b<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncd \/etc\/apache2\nsudo htpasswd -c .htpasswd myuser1\n<\/pre>\n<p>\/etc\/apache2\/sites-enabled\/www2-1-le-ssl.conf \u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u306e\u3067\u4e0b\u8a18\u3092 \u300c<strong>VirtualHost\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306e\u4e2d<\/strong>\u300d\u306b\u8ffd\u8a18\u3059\u308b\u3002<br \/>\n\u5916\u306b\u66f8\u3044\u3066\u3082\u52d5\u304b\u306a\u3044\u3002<br \/>\n\u3082\u3057\u7279\u5b9a\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u307fBASIC\u8a8d\u8a3c\u3092\u304b\u3051\u305f\u3044\u5834\u5408\u306f\u6307\u5b9a\u3059\u308c\u3070OK\u3002<br \/>\n\u6b63\u898f\u8868\u73fe\u3082\u4f7f\u3048\u308b\u3002<br \/>\n\u8a73\u3057\u304f\u306f<a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/ja\/mod\/core.html#directory\" rel=\"noopener noreferrer\" target=\"_blank\">\u3053\u3053\u306b\u66f8\u3044\u3066\u3042\u308b\u3002<\/a><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n  &lt;Directory &quot;\/var\/www\/www2\/&quot;&gt;\n    AuthType Basic\n    AuthName &quot;Password Required&quot;\n    AuthUserFile \/etc\/apache2\/.htpasswd\n    Require valid-user\n  &lt;\/Directory&gt;\n<\/pre>\n<p>\u6700\u5f8c\u306bApache2\u3092\u518d\u8d77\u52d5\u3057\u3066\u5b8c\u4e86<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo systemctl restart apache2\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u305f\u307e\u306b\u3084\u308b\u306e\u3067\u30e1\u30e2\u3002 Ubuntu18.04\u3060\u3051\u3069GCP\u306eComputeEngine\u3067\u3084\u308b\u306e\u3067ufw\u306f\u4f7f\u308f\u306a\u3044\u3002 Firewall\u8a2d\u5b9a\u306e [Allow HTTP\/HTTPS traffic] \u3092ON\u306b\u3057\u3068\u304f\u3002 \u305d\u3057\u3066\u3001\u5148 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-857","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=857"}],"version-history":[{"count":0,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/857\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}