Created
May 13, 2019 07:59
-
-
Save sfrancavilla/30e960d01d082318c6f5604c99579952 to your computer and use it in GitHub Desktop.
Deploy Ruby on Rails apps (+ NGINX) to ECS with Docker - Medium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1.Upstream used to define groups of servers, in this case the rails app, that can be referenced by the proxy_pass | |
upstream rails_app { | |
server app:3000; | |
} | |
# 2.Server part | |
server { | |
# 2.1.Listen to incoming connection on port 80 | |
listen 80; | |
listen [::]:80; | |
return 302 https://$server_name$request_uri; | |
# 2.2.Specify your domain. At the moment just localhost | |
server_name localhost; | |
# 2.3.Specify the public application root | |
root $RAILS_ROOT/public; | |
# 2.4.Specify where Nginx should write its logs | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
# 2.5.Deny requests for files that should never be accessed such as .rb or .log files | |
location ~ /\. { | |
deny all; | |
} | |
location ~* ^.+\.(rb|log)$ { | |
deny all; | |
} | |
# 2.5.Serve static (compiled) assets directly if they exist (for rails production) | |
location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { | |
try_files $uri @rails; | |
access_log off; | |
gzip_static on; | |
expires max; | |
add_header Cache-Control public; | |
add_header Last-Modified ""; | |
add_header ETag ""; | |
break; | |
} | |
# 2.6.send non-static file requests to the app server | |
location / { | |
try_files $uri @rails; | |
} | |
# 2.7.reverse proxy redirecting the request to the rails app, port 3000. | |
location @rails { | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_pass http://rails_app; | |
proxy_read_timeout 900; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment