{"id":265,"date":"2018-11-16T12:55:27","date_gmt":"2018-11-16T09:55:27","guid":{"rendered":"https:\/\/artem.services\/?p=265"},"modified":"2018-12-20T23:38:42","modified_gmt":"2018-12-20T20:38:42","slug":"foreman-ruby-%d0%b8-nginx-%d0%b2-%d0%be%d0%b4%d0%bd%d0%be%d0%bc-docker-%d0%ba%d0%be%d0%bd%d1%82%d0%b5%d0%b9%d0%bd%d0%b5%d1%80%d0%b5","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=265","title":{"rendered":"Foreman &#8212; Ruby \u0438 Nginx \u0432 \u043e\u0434\u043d\u043e\u043c Docker \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-219\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/Config-Examples-Logo.png\" alt=\"\" width=\"937\" height=\"145\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/Config-Examples-Logo.png 937w, https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/Config-Examples-Logo-300x46.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/Config-Examples-Logo-768x119.png 768w\" sizes=\"(max-width: 937px) 100vw, 937px\" \/><\/p>\n<h3>Dockerfile:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nFROM ruby:2.5.0\r\n\r\nWORKDIR \/usr\/src\/app\r\n\r\nCOPY . \/usr\/src\/app\r\n\r\nRUN gem install foreman &amp;&amp; apt update &amp;&amp; apt install nginx -y\r\n\r\nCOPY nginx.conf \/etc\/nginx\r\nCOPY app.conf \/etc\/nginx\/conf.d\/default.conf\r\n\r\nCMD foreman start -f Procfile\r\n\r\nEXPOSE 80\r\n<\/pre>\n<h3>Procfile:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nweb: bundle exec rake db:migrate &amp;&amp; bundle exec rails s -p 3000 -b '0.0.0.0'\r\nnginx: \/usr\/sbin\/nginx -c \/etc\/nginx\/nginx.conf\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<h3>nginx.conf:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nuser root;\r\nworker_processes auto;\r\npid \/run\/nginx.pid;\r\n\r\nevents {\r\n\tworker_connections 2048;\r\n}\r\n\r\nhttp {\r\n\tclient_body_buffer_size 256K;\r\n\tclient_max_body_size 100m;\r\n\r\n\t\r\n\tsend_timeout 300s;\r\n\tsendfile on;\r\n\tkeepalive_timeout 65;\r\n\ttypes_hash_max_size 2048;\r\n\r\n\tinclude \/etc\/nginx\/mime.types;\r\n\tdefault_type application\/octet-stream;\r\n\r\n\tssl_protocols TLSv1 TLSv1.1 TLSv1.2;\r\n\tssl_prefer_server_ciphers on;\r\n\r\n\tlog_format  main  '$remote_addr - $remote_user [$time_local] &quot;$request&quot; '\r\n                    \t  '$status $body_bytes_sent &quot;$http_referer&quot; '\r\n                      \t  '&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;'\r\n                      \t  '$request_time $upstream_response_time $pipe';\r\n\r\n\r\n\r\n\taccess_log \/var\/log\/nginx\/access.log main;\r\n\terror_log \/var\/log\/nginx\/error.log;\r\n\r\n\tgzip on;\r\n\tgzip_disable &quot;msie6&quot;;\r\n\t\r\n\tgzip_static on;\r\n\tgzip_vary on;\r\n\tgzip_proxied any;\r\n\tgzip_comp_level 9;\r\n\tgzip_buffers 16 8k;\r\n\tgzip_http_version 1.0;\r\n\tgzip_types text\/plain text\/css application\/json image\/png image\/x-icon image\/svg+xml image\/gif image\/jpeg application\/javascript text\/xml application\/xml application\/xml+rss text\/javascript;\r\n\r\n\tinclude \/etc\/nginx\/conf.d\/*.conf;\r\n}\r\n\r\ndaemon off;\r\n<\/pre>\n<h3>app.conf:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nupstream ruby {\r\n    server 127.0.0.1:3000 fail_timeout=0;\r\n}\r\n\r\nserver {\r\n    listen 80 default_server;\r\n    access_log \/usr\/src\/app\/log\/access.nginx.log;\r\n    error_log \/usr\/src\/app\/log\/error.nginx.log;\r\n    root \/usr\/src\/app\/public;\r\n\r\n    location ~* \\.(mp4|pdf|jpg|jpeg|gif|png|ico|css|bmp|swf|js|html|txt|svg)$ {\r\n        root \/usr\/src\/app\/public;\r\n        expires max;\r\n    }\r\n \r\n    location \/ {\r\n        try_files $uri\/index.html $uri.html $uri @ruby;\r\n    }\r\n\r\n    location @ruby {\r\n        proxy_pass http:\/\/ruby;\r\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n        proxy_set_header Host $http_host;\r\n        proxy_redirect off;\r\n    }\r\n}\r\n<\/pre>\n<h5>\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0435\u0442\u0441\u044f <strong>SSL<\/strong><\/h5>\n<blockquote><p>\u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0432 <strong>EXPOSE<\/strong> \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u0440\u0442 <strong>443<\/strong><\/p><\/blockquote>\n<h3>app.conf:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nupstream ruby {\r\n    server 127.0.0.1:3000 fail_timeout=0;\r\n}\r\n\r\n# HTTP host\r\nserver {\r\n    listen 0.0.0.0:80;\r\n    server_name artem.services;\r\n\r\n    server_tokens off;\r\n\r\n    return 301 https:\/\/$http_host$request_uri;\r\n    access_log \/usr\/src\/app\/log\/access.nginx.log;\r\n    error_log \/usr\/src\/app\/log\/error.nginx.log;\r\n}\r\n\r\n# HTTPS host\r\nserver {\r\n    listen 0.0.0.0:443 ssl;\r\n    server_name artem.services;\r\n\r\n    access_log \/usr\/src\/app\/log\/access.nginx.log;\r\n    error_log \/usr\/src\/app\/log\/error.nginx.log;\r\n\r\n    ssl on;\r\n    ssl_certificate \/etc\/nginx\/letsencrypt\/live\/artem.services\/fullchain.pem;\r\n    ssl_certificate_key \/etc\/nginx\/letsencrypt\/live\/artem.services\/privkey.pem;\r\n\r\n    location \/ {\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n        proxy_set_header Host $http_host;\r\n        proxy_set_header X-NginX-Proxy true;\r\n        proxy_set_header X-Forwarded-Proto $scheme;\r\n\r\n        proxy_pass https:\/\/ruby;\r\n        proxy_redirect off;\r\n\r\n        proxy_http_version 1.1;\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dockerfile: Procfile: &nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[4,61,10,62,60],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/265"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=265"}],"version-history":[{"count":7,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/265\/revisions"}],"predecessor-version":[{"id":383,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/265\/revisions\/383"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}