Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of nginx configuration for proxing to a rails application. Don't forget to change <template_strings>
server {
listen <ip>:<port>;
server_name <domain>;
charset off;
set $root_path <path_to_rails_application>/public;
disable_symlinks if_not_owner from=$root_path;
root $root_path;
access_log <path_to_logs_dir>/<domain>-access.log;
error_log <path_to_logs_dir>/<domain>-error.log notice;
# Assets
location ~* ^.+\.(jpg|jpeg|gif|png|svg|svg.gz|js|css|mp3|mp4|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|txt|ico|eot|eot.gz|ttf|ttf.gz|woff|woff2|pdf|csv|xls|xlsx|doc|docx)$ {
try_files $uri $uri/ @backend;
expires 7d;
access_log off;
log_not_found off;
gzip_static on;
}
location / {
proxy_pass http://127.0.0.1:<rails_application_port>;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
# ActionCable
location /cable {
proxy_pass http://127.0.0.1:<rails_application_port>;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location @backend {
proxy_pass http://127.0.0.1:<rails_application_port>;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.