Last active
November 9, 2018 14:32
-
-
Save Apmyp/7bffe5d12cb58e5347c344a1c41e7b73 to your computer and use it in GitHub Desktop.
Example of nginx configuration for proxing to a rails application. Don't forget to change <template_strings>
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
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