Last active
September 28, 2023 18:21
-
-
Save ericboehs/709c8c97ef37284146c7e36815c1c254 to your computer and use it in GitHub Desktop.
Testing nginx locally with Rails
This file contains hidden or 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
# frozen_string_literal: true | |
# This file is used by Rack-based servers to start the application. | |
require_relative 'config/environment' | |
map Rails.application.config.relative_url_root || '/' do | |
run Rails.application | |
Rails.application.load_server | |
end |
This file contains hidden or 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
user nginx; | |
worker_processes auto; | |
error_log /var/log/nginx/error.log debug; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
keepalive_timeout 65; | |
#gzip on; | |
server { | |
listen 80; | |
server_name localhost; | |
location /atlas { | |
proxy_set_header Host $host:8082; | |
proxy_set_header X-Forwarded-Host localhost:3000; | |
proxy_pass http://host.docker.internal:3000/atlas; | |
} | |
} | |
include /etc/nginx/conf.d/*.conf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was working on a little Rails project called Atlas and we wanted to mount it at https://our.domain.com/atlas via our nginx rev proxy.
Rails had some interesting issues with being mounted at a subdirectory. To test this out, I temporarily added an nginx.conf file to my Rails root and ran:
For local testing, I ran:
In prod, make sure you set
RAILS_SERVE_STATIC_FILES=true
andRAILS_RELATIVE_URL_ROOT=/atlas
in your ENV.