{"id":11197,"date":"2022-05-01T03:49:24","date_gmt":"2022-04-30T18:49:24","guid":{"rendered":"http:\/\/www.webcyou.com\/?p=11197"},"modified":"2022-05-02T16:37:30","modified_gmt":"2022-05-02T07:37:30","slug":"ubuntu-20-04-lts-%e3%82%b5%e3%83%bc%e3%83%90%e6%a7%8b%e7%af%89-nginx%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=11197","title":{"rendered":"Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 Nginx\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb"},"content":{"rendered":"<p>\u524d\u56de\u306e<a href=\"https:\/\/www.webcyou.com\/?p=11191\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 \u521d\u671f\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/a>\u306e\u7d9a\u304d\u3067\u3059\u3002<\/p>\n<h4>\u30e1\u30cb\u30e5\u30fc<\/h4>\n<ul>\n<li><a href=\"https:\/\/www.webcyou.com\/?p=11191\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 \u521d\u671f\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/a><\/li>\n<li><a href=\"https:\/\/www.webcyou.com\/?p=11197\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 Nginx\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li>\n<li><a href=\"https:\/\/www.webcyou.com\/?p=11205\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 Let\u2019s Encrypt\u3067SSL\/TLS\u5316<\/a><\/li>\n<li><a href=\"https:\/\/www.webcyou.com\/?p=11211\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 Postfix\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li>\n<li><a href=\"https:\/\/www.webcyou.com\/?p=11218\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 Dovecot\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li>\n<li><a href=\"https:\/\/www.webcyou.com\/?p=11221\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 Postfix SASL\u8a8d\u8a3c<\/a><\/li>\n<li><a href=\"https:\/\/www.webcyou.com\/?p=11230\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 Postfix Let\u2019s Encrypt\u3067TLS\u5316<\/a><\/li>\n<li><a href=\"https:\/\/www.webcyou.com\/?p=11234\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 DKIM\u3001DMARC\u3092\u8a2d\u5b9a\u3059\u308b<\/a><\/li>\n<\/ul>\n<h4>Nginx\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h4>\n<p>\u30ed\u30fc\u30ab\u30eb\u30d1\u30c3\u30b1\u30fc\u30b8\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u66f4\u65b0\u3057\u3001nginx\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo apt update\r\n$ sudo apt install nginx<\/pre>\n<h4>\u30d5\u30a1\u30a4\u30a2\u30a6\u30a9\u30fc\u30eb\u306e\u8abf\u6574<\/h4>\n<p>ufw\u3067\u4f7f\u7528\u3067\u304d\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u69cb\u6210\u3092\u78ba\u8a8d\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo ufw app list<\/pre>\n<p>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u306e\u4e00\u89a7\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">Output\r\nAvailable applications:\r\n  Nginx Full\r\n  Nginx HTTP\r\n  Nginx HTTPS\r\n  OpenSSH<\/pre>\n<p>Nginx\u306b\u306f3\u3064\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li><strong>Nginx Full<\/strong>: \u30dd\u30fc\u30c880\u3068\u30dd\u30fc\u30c8443\u306e\u4e21\u65b9\u3092\u958b\u653e\u3002<\/li>\n<li><strong>Nginx HTTP<\/strong>: \u30dd\u30fc\u30c880\u306e\u307f\u958b\u653e\u3002<\/li>\n<li><strong>Nginx HTTPS<\/strong>: \u30dd\u30fc\u30c8443\u306e\u307f\u958b\u653e\u3002<\/li>\n<\/ul>\n<p>\u5f8c\u307b\u3069\u3001HTTPS\u306e\u8a2d\u5b9a\u3082\u884c\u3046\u306e\u3067\u3001Nginx Full\u3092\u9078\u629e\u3057\u6709\u52b9\u306b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo ufw allow 'Nginx Full'<\/pre>\n<p>\u5909\u66f4\u5f8c\u3001\u9069\u5fdc\u3055\u308c\u3066\u3044\u308b\u306e\u3092\u78ba\u8a8d\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo ufw status<\/pre>\n<p>\u8a31\u53ef\u3055\u308c\u305fHTTP\u30c8\u30e9\u30d5\u30a3\u30c3\u30af\u304c\u51fa\u529b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">Output\r\nStatus: active\r\n\r\nTo                         Action      From\r\n--                         ------      ----\r\nOpenSSH                    ALLOW       Anywhere\r\nNginx HTTP                 ALLOW       Anywhere\r\nOpenSSH (v6)               ALLOW       Anywhere (v6)\r\nNginx HTTP (v6)            ALLOW       Anywhere (v6)<\/pre>\n<h4>Web\u30b5\u30fc\u30d0\u30fc\u306e\u78ba\u8a8d<\/h4>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5f8cNginx\u306f\u81ea\u52d5\u8d77\u52d5\u3059\u308b\u306e\u3067\u3001\u8d77\u52d5\u78ba\u8a8d\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ systemctl status nginx<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">Output\r\n\u25cf nginx.service - A high performance web server and a reverse proxy server\r\n   Loaded: loaded (\/lib\/systemd\/system\/nginx.service; enabled; vendor preset: enabled)\r\n   Active: active (running) since Wed 2022-04-13 18:21:02 UTC; 23h ago\r\n     Docs: man:nginx(8)\r\n Main PID: 2369 (nginx)\r\n    Tasks: 2 (limit: 1153)\r\n   Memory: 6.6M\r\n   CGroup: \/system.slice\/nginx.service\r\n           \u251c\u25002369 nginx: master process \/usr\/sbin\/nginx -g daemon on; master_process on;\r\n           \u2514\u25002380 nginx: worker process<\/pre>\n<p>\u30b5\u30fc\u30d0\u30fc\u306eIP\u30a2\u30c9\u30ec\u30b9\u3092icanhazip.com\u30c4\u30fc\u30eb\u3092\u7528\u3044\u3066\u78ba\u8a8d\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ curl -4 icanhazip.com<\/pre>\n<p>\u30d6\u30e9\u30a6\u30b6\u306e\u30a2\u30c9\u30ec\u30b9\u30d0\u30fc\u306bIP\u30a2\u30c9\u30ec\u30b9\u3092\u5165\u529b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">http:\/\/your_server_ip<\/pre>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u306eNginx\u30da\u30fc\u30b8\u306e\u8868\u793a\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2022\/04\/nginx_default.png\" alt=\"\" width=\"577\" height=\"212\" class=\"alignnone size-full wp-image-11198\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2022\/04\/nginx_default.png 577w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2022\/04\/nginx_default-300x110.png 300w\" sizes=\"auto, (max-width: 577px) 100vw, 577px\" \/><\/p>\n<h4>\u30b5\u30fc\u30d0\u30fc\u30d6\u30ed\u30c3\u30af\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/h4>\n<p>Nginx\u306b\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u6709\u52b9\u306b\u306a\u3063\u3066\u3044\u308b\u30b5\u30fc\u30d0\u30fc\u30d6\u30ed\u30c3\u30af\u3068\u306f\u5225\u306b`\/var\/www`\u5185\u306b\u65b0\u305f\u306b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u9020\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\uff08your_domain\u306f\u53d6\u5f97\u3001\u8a2d\u5b9a\u3057\u305f\u30c9\u30e1\u30a4\u30f3\uff09<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo mkdir -p \/var\/www\/your_domain\/html<\/pre>\n<p>$USER \u74b0\u5883\u5909\u6570\u3092\u7528\u3044\u3066\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u6240\u6709\u6a29\u3092\u5272\u308a\u5f53\u3066\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo chown -R $USER:$USER \/var\/www\/your_domain\/html<\/pre>\n<p>\u6240\u6709\u8005\u306b\u306f\u8aad\u307f\u53d6\u308a\u30fb\u66f8\u304d\u8fbc\u307f\u30fb\u5b9f\u884c\u53ef\u80fd\u6a29\u9650\u3092\u3001\u30b0\u30eb\u30fc\u30d7\u306b\u306f\u8aad\u307f\u53d6\u308a\u30fb\u5b9f\u884c\u53ef\u80fd\u6a29\u9650\u306e\u307f\u3092\u305d\u308c\u305e\u308c\u4ed8\u4e0e\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo chmod -R 755 \/var\/www\/your_domain<\/pre>\n<p>\u30b5\u30f3\u30d7\u30eb index.html \u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ vim \/var\/www\/your_domain\/html\/index.html<\/pre>\n<p>\u30b5\u30f3\u30d7\u30ebHTML<br \/>\n\/var\/www\/your_domain\/html\/index.html<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;html&gt;&lt;head&gt;&lt;title&gt;My Home page&lt;\/title&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;Welcome! My website&lt;\/h1&gt;&lt;\/body&gt;&lt;\/html&gt;<\/pre>\n<p>Nginx\u306e\u30b5\u30fc\u30d0\u30fc\u30d6\u30ed\u30c3\u30af\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo vim \/etc\/nginx\/sites-available\/your_domain<\/pre>\n<p>\u69cb\u6210\u30d6\u30ed\u30c3\u30af\u3092\u4f5c\u6210<br \/>\n\/etc\/nginx\/sites-available\/your_domain<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">server {\r\n        listen 80;\r\n        listen &#x5B;::]:80;\r\n\r\n        root \/var\/www\/your_domain\/html;\r\n        index index.html index.htm index.nginx-debian.html;\r\n\r\n        server_name your_domain www.your_domain;\r\n\r\n        location \/ {\r\n                try_files $uri $uri\/ =404;\r\n        }\r\n}<\/pre>\n<p>sites-enabled \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30ea\u30f3\u30af\u3092\u4f5c\u6210\u3057\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u6709\u52b9\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo ln -s \/etc\/nginx\/sites-available\/your_domain \/etc\/nginx\/sites-enabled\/<\/pre>\n<p>\u30b5\u30fc\u30d0\u30fc\u540d\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u30cf\u30c3\u30b7\u30e5\u30d0\u30b1\u30c3\u30c8\u30e1\u30e2\u30ea\u306e\u554f\u984c\u3092\u56de\u907f\u3059\u308b\u305f\u3081\u306b\u3001 \/etc\/nginx\/nginx.conf \u30d5\u30a1\u30a4\u30eb\u3092\u4fee\u6b63\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo vim \/etc\/nginx\/nginx.conf<\/pre>\n<p>server_names_hash_bucket_size \u306e\u30b3\u30e1\u30f3\u30c8\u3092\u5916\u3057\u307e\u3059\u3002<\/p>\n<p>\/etc\/nginx\/nginx.conf<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">...\r\nhttp {\r\n    ...\r\n    server_names_hash_bucket_size 64;\r\n    ...\r\n}\r\n...<\/pre>\n<p>Nginx\u30d5\u30a1\u30a4\u30eb\u306b\u69cb\u6587\u30a8\u30e9\u30fc\u304c\u306a\u3044\u3053\u3068\u3092\u30c6\u30b9\u30c8\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo nginx -t<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\r\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/pre>\n<p>\u554f\u984c\u306a\u3051\u308c\u3070\u3001Nginx\u3092\u518d\u8d77\u52d5\u3057\u3066\u5909\u66f4\u3092\u6709\u52b9\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo systemctl restart nginx<\/pre>\n<p>http:\/\/your_domain\u307e\u305f\u306fhttp:\/\/www.your_domain \u3092\u30d6\u30e9\u30a6\u30b6\u3067\u78ba\u8a8d\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2022\/04\/mypage.png\" alt=\"\" width=\"438\" height=\"73\" class=\"alignnone size-full wp-image-11199\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2022\/04\/mypage.png 438w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2022\/04\/mypage-300x50.png 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/p>\n<h4>\u305d\u306e\u4ed6\u306e\u8a2d\u5b9a<\/h4>\n<p>\u3053\u308c\u3089\u306e\u8a2d\u5b9a\u306f\u4efb\u610f\u3067\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h5>Access Log\u8a2d\u5b9a<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo vim \/etc\/nginx\/nginx.conf<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">location ~* \\.(?:css(\\.map)?|js(\\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {\r\n    expires 7d;\r\n    access_log off;\r\n}\r\n\r\nlocation ~* \\.(?:svgz?|ttf|ttc|otf|eot|woff|woff2)$ {\r\n    add_header Access-Control-Allow-Origin \"*\";\r\n    expires 7d;\r\n    access_log off;\r\n}<\/pre>\n<h5>Gzip\u8a2d\u5b9a<\/h5>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u89e3\u9664\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ sudo vim \/etc\/nginx\/nginx.conf<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">gzip on;\r\n\r\n# gzip_vary on;\r\n# gzip_proxied any;\r\n# gzip_comp_level 6;\r\n# gzip_buffers 16 8k;\r\n# gzip_http_version 1.1;\r\n# gzip_types text\/plain text\/css application\/json application\/javascript text\/xml application\/xml application\/xml+rss text\/javascript;<\/pre>\n<p>\u7d9a\u3044\u3066\u3001Let\u2019s Encrypt\u3067\u3001TLS\u8a2d\u5b9a\u3092\u884c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/?p=11205\">Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 Let\u2019s Encrypt\u3067SSL\/TLS\u5316<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306eUbuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 \u521d\u671f\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u306e\u7d9a\u304d\u3067\u3059\u3002 \u30e1\u30cb\u30e5\u30fc Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 \u521d\u671f\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7 Ubuntu 20.04 LTS \u30b5\u30fc\u30d0\u69cb\u7bc9 \u2013 Ngi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11192,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[248],"tags":[221,44,45,293],"class_list":{"0":"post-11197","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-ubuntu","8":"tag-linux","9":"tag-web","11":"tag-293"},"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/11197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11197"}],"version-history":[{"count":6,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/11197\/revisions"}],"predecessor-version":[{"id":11259,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/11197\/revisions\/11259"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/media\/11192"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}