How to Configure Nginx for One HTTP Page on a Mostly HTTPS Site

Abstract: Configure Nginx to serve a single HTTP page alongside an HTTPS-only site by defining separate server blocks for ports 80 and 443.

Created: 2026-09-03 by
To configure Nginx for a single HTTP page on an otherwise HTTPS-only site, you must define two separate server blocks within your configuration file. The first block listens on port 80 and serves the specific static content or proxy pass required for that page. The second block listens on port 443 with SSL enabled, handling all other requests securely. This dual-protocol setup ensures that only the designated resource remains accessible via unencrypted HTTP while the rest of the site maintains strict security standards.

Understanding the Dual Protocol Requirement

In modern web architecture, enforcing HTTPS across the entire domain is standard practice to protect user data and improve search engine rankings. However, legacy systems, specific API endpoints, or internal tools sometimes require HTTP access for compatibility reasons. Attempting to mix these protocols in a single server block often leads to redirect loops or security warnings. Therefore, isolating the HTTP requirement into its own dedicated context is the most robust solution. By separating the configurations, you prevent accidental exposure of sensitive resources. If you were to allow HTTP on the main server block, every request would fall back to unencrypted communication unless explicitly redirected. Instead, we create a narrow exception path. This approach aligns with best practices seen in complex deployments, such as those discussed in Configuring SSL Passthrough with Certificates on Nginx Reverse Proxy for Paperless-ngx, where precise control over traffic flow is essential.

Step-by-Step Configuration

The core of this solution lies in editing your Nginx configuration file, typically located at /etc/nginx/sites-available/default or a custom file included in the main nginx.conf. You will need to add two distinct server blocks. First, create the HTTP server block. This block should listen on port 80 and specify the server_name matching your domain. Inside this block, use the root directive to point to the local storage directory containing the single HTML file you wish to serve. Alternatively, if the page requires dynamic processing, use a location block with proxy_pass to forward the request to an upstream service. Crucially, do not include any SSL directives here. Second, create the HTTPS server block. This block listens on port 443 with the ssl parameter enabled. You must provide paths to your certificate and private key files using ssl_certificate and ssl_certificate_key. Within this block, define the default behavior for all other requests. You can set a generic root directory or use try_files to handle routing. To ensure security, add headers like Strict-Transport-Security (HSTS) to force browsers to use HTTPS for subsequent visits. Here is a conceptual structure for the configuration:
server {
    listen 80;
    server_name example.com www.example.com;

    # Serve the single HTTP page
    location /special-page.html {
        root /var/www/html;
        try_files $uri =404;
    }
}

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

    ssl_certificate /etc/ssl/certs/example.com.crt;
    ssl_certificate_key /etc/ssl/private/example.com.key;

    # Default HTTPS behavior for the rest of the site
    location / {
        root /var/www/secure-site;
        index index.html;
    }
}
After saving the file, test the syntax by running sudo nginx -t. If the test passes, reload Nginx using sudo systemctl reload nginx. This applies the changes without dropping active connections.

Handling Local Storage Paths

When referencing local storage, ensure that the Nginx user (usually www-data) has read permissions on the target directory. Incorrect permissions are a common cause of 403 Forbidden errors. Use ls -l to verify ownership and adjust with chmod or chown if necessary. For example, sudo chown -R www-data:www-data /var/www/html ensures the web server can access the files.

Security Considerations and Best Practices

While allowing HTTP is sometimes necessary, it introduces risks. Attackers can perform man-in-the-middle attacks on unencrypted traffic. To mitigate this, limit the HTTP block to the absolute minimum required. Do not expose administrative panels or login forms over HTTP. Additionally, consider implementing HSTS preload lists for your domain to ensure that even the first visit uses HTTPS, though this may conflict with the need for an initial HTTP fallback. For sites managing multiple services, such as reverse proxies, issues like trailing slash redirects can complicate dual-protocol setups. Reviewing guides on Nginx Reverse Proxy Strips Path Prefix Trailing Slash Redirect in Docker Compose Hugo Deployment can help troubleshoot unexpected redirection behaviors when mixing protocols.

Troubleshooting Common Issues

If the HTTP page does not load, check the Nginx error log located at /var/log/nginx/error.log. Look for permission denied messages or file not found errors. Ensure that the firewall allows inbound traffic on both port 80 and 443. On Linux systems, use ufw allow 80/tcp and ufw allow 443/tcp to open these ports. Another common issue is browser caching. Browsers aggressively cache HSTS policies. If you previously enforced HTTPS on the entire domain, your browser might refuse to connect to the HTTP port entirely. Clear your browser cache or use an incognito window to test the new configuration.

Frequently Asked Questions

Can I use a single server block for both HTTP and HTTPS?

No, it is strongly discouraged because it complicates security policy enforcement. Mixing them often leads to accidental exposure of secure content over unencrypted channels. Separate blocks ensure clear isolation between public and protected resources.

How do I handle SSL certificates for the HTTP block?

You do not need SSL certificates for the HTTP block since it does not encrypt traffic. The HTTPS block handles all cryptographic operations. Keeping the blocks separate prevents configuration errors related to missing certificate paths in the wrong context.

What happens if I forget to open port 80 in my firewall?

Users attempting to access the HTTP page will receive a connection timeout or refused error. Ensure your cloud provider’s security groups and local firewall rules permit TCP traffic on port 80 alongside port 443.

Can I redirect HTTP to HTTPS for all pages except one?

Yes, but it is more complex. You would need a global redirect rule in the HTTP server block with an exception for the specific URI. This approach is prone to errors and is generally less maintainable than using separate server blocks.

Does this configuration affect SEO performance?

Search engines prefer HTTPS, so keeping most of the site encrypted is beneficial. However, ensuring the HTTP page is canonicalized correctly helps avoid duplicate content issues. Use rel="canonical" tags to point to the preferred URL version.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More