DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
VGSources
Blog

How to Configure SSL on Nginx for a Rails Application

A complete Nginx and Rails SSL guide: install the certificate and key, preserve ACME validation, proxy HTTPS correctly to Puma or Unicorn, prevent redirect loops, and test automatic Certbot renewal.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Terminate TLS at Nginx, proxy requests to your Rails application server, and tell Rails that the original request was HTTPS. The essential pieces are a certificate and protected private key in a listen 443 ssl server block, an HTTP listener that serves ACME challenges and redirects normal traffic, forwarding headers such as X-Forwarded-Proto https, and config.force_ssl = true in production.

What the finished setup does

A typical deployment has four network steps:

  1. A browser resolves your hostname to the Nginx server.
  2. Nginx accepts the TLS connection on port 443 and proves the hostname with the certificate and private key.
  3. Nginx forwards the decrypted HTTP request to Puma, Unicorn, or another Rails application server on a private address and port.
  4. Rails treats the original request as HTTPS, generates secure URLs, and redirects any request that arrived without HTTPS.

Nginx is the TLS termination point in this design. Its HTTPS server block needs listen 443 ssl, a server_name, ssl_certificate, and ssl_certificate_key. Nginx’s HTTPS documentation explains that the private key must be restricted but readable by the Nginx master process: Configuring HTTPS servers.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The Rails process does not need to hold the public certificate when Nginx terminates TLS. It does, however, need the forwarding information that identifies the client’s original host, address, and scheme.

Prerequisites and deployment decisions

  • A DNS A or AAAA record for every hostname you will serve, pointing to the Nginx machine.
  • Inbound TCP access to ports 80 and 443 through the host firewall, cloud firewall, and any upstream load balancer.
  • A running Rails application server, such as Puma or Unicorn, listening on a local address and known port.
  • A certificate covering every hostname clients will use, plus its matching private key.
  • Permission to edit Nginx configuration and reload the service.
  • A plan for certificate renewal and a test of that plan before the first unattended renewal.

Decide whether TLS ends at Nginx or continues from Nginx to the Rails upstream. Terminating at Nginx is the simplest arrangement for an application server bound to loopback or a private network. End-to-end TLS can be appropriate when the upstream crosses an untrusted or separately administered network, but it requires Nginx to validate or otherwise manage a second certificate connection. The configuration below documents the Nginx-termination pattern.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Point DNS to Nginx and verify reachability

Create DNS records for the exact names in your certificate, such as example.com and www.example.com. Allow time for the records to resolve according to their TTL. Confirm that each name resolves to the intended server rather than an old address or a different proxy.

Port 80 remains important even when every normal request is redirected to HTTPS. The HTTP-01 ACME challenge used by Certbot must be able to reach a file below /.well-known/acme-challenge/ over HTTP. Do not block that path with a blanket redirect rule, authentication requirement, or application route.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Before requesting a certificate, check that the webroot you intend to use is served by Nginx and that the firewall allows port 80. A failed challenge is usually a DNS, routing, firewall, or location-matching problem rather than a Rails problem.

Obtain and protect the certificate and key

For a certificate managed by Certbot, the live certificate directory commonly contains a full chain and a private key. The exact directory depends on the certificate name and the operating system packaging; use the paths created on your server rather than copying the example paths blindly.

The certificate file presented to clients should normally be the full chain, while the key file must be the matching private key. Keep the key readable by the Nginx master process and inaccessible to ordinary users. Avoid placing it in a world-readable application directory, committing it to source control, or copying it into logs and support tickets.

Nginx’s guidance states: “The private key is a secure entity and should be stored in a file with restricted access, however, it must be readable by nginx’s master process.” See NGINX Configuring HTTPS servers for the certificate and key requirements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

When permissions are changed, test the configuration as the service will load it. A key that is too restrictive for the Nginx master causes an error at configuration test or reload time; a key that is too permissive creates an avoidable credential exposure.

Build the Nginx server blocks

Use one HTTP server block for redirects and ACME validation and one HTTPS server block for TLS and proxying. Replace the domains, certificate paths, webroot, and upstream port with values from your deployment.

server {
    listen 80;
    server_name example.com www.example.com;

    location ^~ /.well-known/acme-challenge/ {
        root /var/www/letsencrypt;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name example.com www.example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_pass http://127.0.0.1:3000;
    }
}

This is an illustrative pattern, not a universal directory layout or application port. The root under the challenge location must match the webroot used by your ACME client. The upstream in the example is local Puma on port 3000; use the address and port where your Rails server actually listens.

HTTP listener: preserve ACME, redirect everything else

The server_name list must include every HTTP hostname you want to redirect. The challenge location is more specific than location /, so a validation file can be served without being sent through the redirect or Rails application. The remaining requests receive a 301 response while preserving the original host and URI through $host and $request_uri.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you use a different validation method, such as DNS-01, the challenge location is not required for issuance. Keeping a simple port-80 redirect is still useful for visitors and for clients that first attempt HTTP.

HTTPS listener: certificate, protocol, and proxy

listen 443 ssl tells Nginx to negotiate TLS for this virtual host. Set ssl_certificate to the certificate chain and ssl_certificate_key to its matching private key. TLS 1.2 and TLS 1.3 are the modern protocol settings documented by Nginx; the example explicitly enables those two versions.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

The proxy directives preserve the data Rails needs:

  • Host $http_host forwards the hostname (and, when supplied by the client, its port).
  • X-Forwarded-For $proxy_add_x_forwarded_for appends the connecting address to the forwarding chain.
  • X-Forwarded-Proto https tells Rails that the client-to-Nginx connection used HTTPS, even though Nginx-to-Rails is plain HTTP on the private hop.
  • proxy_pass points to the Rails application server, not to a public DNS name that could route the request back through Nginx.

Do not set X-Forwarded-Proto to http in this HTTPS location. Doing so makes Rails believe the original request was insecure and is a common cause of redirects that never settle.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Enable HTTPS behavior in Rails

In the production configuration, enable:

config.force_ssl = true

Rails adds the ActionDispatch::SSL middleware when config.force_ssl = true. The middleware redirects HTTP requests and uses HTTPS as the default URL protocol. The Rails API documents this behavior at ActionDispatch::SSL, and the configuration guide documents the setting at Rails Configuration.

Set the option in the environment configuration that actually runs in production, then restart or reload the Rails application processes so they read the changed configuration. Keep the Nginx forwarding header and the Rails setting together: Rails can enforce HTTPS only when it can distinguish the original client scheme from the internal proxy connection.

Validate the configuration before reloading

  1. Check syntax and referenced files with sudo nginx -t. Fix every reported error before proceeding. Typical failures include a misspelled directive, an unreadable key, a missing certificate file, or a duplicate listen/server definition.
  2. Reload rather than stopping the service, for example with sudo systemctl reload nginx, after the test succeeds. A reload lets existing connections finish while workers adopt the new configuration.
  3. Request the HTTPS endpoint with a client such as curl -I https://example.com/. Expect a response from the Rails application rather than an Nginx certificate or upstream error.
  4. Request the HTTP endpoint with curl -I http://example.com/. Normal paths should return a 301 whose Location uses HTTPS. A challenge path must remain reachable from the configured webroot when a validation file exists.
  5. Exercise a Rails page that generates absolute URLs, redirects, links, or asset URLs. Those URLs should use https://, not http://.

Test every hostname separately. A certificate can be valid for one name while the Nginx virtual-host selection or DNS record for another name points somewhere else.

Issue and renew certificates with Certbot

Certbot’s HTTP-01 flow writes a token file into the selected webroot and asks the certificate authority to retrieve it through port 80. The Nginx challenge location must expose that same directory. Certbot describes the validation and renewal process in its documentation: Certbot documentation (PDF).

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

A webroot-based issuance command follows this pattern; adapt the path and names to your host:

sudo certbot certonly --webroot 
  -w /var/www/letsencrypt 
  -d example.com 
  -d www.example.com

The command obtains or updates the certificate without asking Certbot to rewrite your Nginx virtual hosts. After issuance, point ssl_certificate and ssl_certificate_key at the generated files, run nginx -t, and reload Nginx.

Renewal is normally unattended when the Certbot package installs its scheduled timer or job. Do not assume the schedule works merely because issuance succeeded once. Perform a dry run:

sudo certbot renew --dry-run

A successful dry run exercises the renewal path without replacing the live certificate. Also verify that a renewal deploy hook or equivalent reloads Nginx after a new certificate is installed; otherwise Nginx can continue serving the old certificate until its next restart. The hook must run nginx -t before reloading so a failed configuration cannot silently interrupt service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

HTTP-01 versus DNS-01 validation

Validation method What it needs Best fit Operational caution
HTTP-01 Port 80 reachable publicly and /.well-known/acme-challenge/ served from the configured webroot Hosts where Nginx can expose a stable challenge directory Redirects, firewalls, alternate proxies, or incorrect webroots can prevent the authority from retrieving the token
DNS-01 Ability to publish the required DNS challenge record Wildcards or hosts where port 80 cannot serve a challenge DNS automation and credentials need their own access controls and failure monitoring

Choose one method deliberately. If HTTP-01 is used, keep the challenge location working during certificate renewal, not only during initial issuance. If DNS-01 is used, the Nginx redirect does not validate ownership; the DNS record does.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

One host versus multiple SNI hostnames

For a single site, one server_name list can cover the apex and its www alias when the certificate includes both names. For several sites on one Nginx instance, create a matching HTTPS server block for each certificate and hostname set. Nginx uses Server Name Indication (SNI) during the TLS handshake to select the certificate and virtual host.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Keep the HTTP names aligned with the HTTPS names. A missing name can fall through to a default server and present the wrong certificate or redirect to the wrong host. When adding a hostname, update DNS, the certificate’s name list, both server blocks, and any Rails host-authorization or URL settings that restrict accepted hosts.

TLS termination at Nginx versus TLS to Rails

Arrangement Connection from client Connection to Rails Key consideration
TLS terminated at Nginx HTTPS HTTP on loopback or a trusted private network Simpler certificate handling; Rails must receive X-Forwarded-Proto https
End-to-end TLS HTTPS HTTPS Protects the second hop but requires an HTTPS upstream, certificate validation, and additional Nginx settings

For the first arrangement, never infer security from the internal URL alone. Rails sees the proxy connection unless Nginx supplies the original scheme. For the second arrangement, configure the upstream as HTTPS only when the Rails server is actually presenting a certificate and Nginx is prepared to validate or intentionally trust it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot the common failures

Redirect loop between HTTP and HTTPS

Inspect the request headers arriving at Rails and confirm that the HTTPS location sends X-Forwarded-Proto https. If Rails receives http or no scheme header, force_ssl redirects to HTTPS even though the browser is already using HTTPS at Nginx. Also check that another proxy in front of Nginx is not overwriting the header and that the HTTP block redirects only normal requests.

Certificate is wrong or appears to belong to another site

Verify DNS for the hostname, the exact server_name, and which Nginx server is answering on port 443. On a multi-site host, a missing SNI name or a default virtual host can select a different certificate. Confirm that the configured certificate contains every requested name and that Nginx was reloaded after changing the certificate paths.

Nginx will not reload

Run sudo nginx -t and read the first error reported. A missing file, invalid directive, duplicate listen option, or key-permission error must be fixed before reload. Check that symbolic links in a certificate’s live directory still resolve to files readable by the Nginx master process.

ACME challenge returns 301, 404, or an application page

Request a known test file below /.well-known/acme-challenge/ over HTTP and confirm that it is served from the intended webroot. Ensure the challenge location appears in the correct port-80 server block, the hostname resolves to that server, and no upstream proxy or access rule intercepts it. A 404 usually means the webroot or file name does not match; an application page means the request fell through to location /.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Rails generates HTTP links or reports an insecure request

Check Host, X-Forwarded-For, and especially X-Forwarded-Proto in the proxy configuration. Confirm that the running environment has config.force_ssl = true and that the application processes were restarted after the change. Test a page that creates an absolute URL rather than relying only on the browser’s address bar.

502 Bad Gateway

A valid certificate does not prove that Rails is reachable. Confirm that Puma, Unicorn, or the chosen server is running, listening on the address and port in proxy_pass, and accessible from the Nginx worker. A loopback-only upstream is appropriate when both processes share a machine; use the private address when they are separate hosts.

Operational checklist

  • Every served hostname resolves to the intended Nginx server.
  • Ports 80 and 443 are reachable through all firewalls and load balancers.
  • The certificate covers every hostname and the private key matches it.
  • The key is restricted to the Nginx master process and not ordinary users.
  • The port-80 block serves ACME challenges and redirects other paths.
  • The port-443 block enables TLS 1.2 and TLS 1.3, references the correct files, and proxies to the real Rails port.
  • Host, X-Forwarded-For, and X-Forwarded-Proto https are forwarded.
  • config.force_ssl = true is active in the production environment.
  • nginx -t passes before every reload.
  • HTTPS responses, HTTP redirects, Rails-generated URLs, and every hostname have been tested.
  • certbot renew --dry-run succeeds, and successful renewal reloads Nginx.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.