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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Run Magento Open Source on Ubuntu with Nginx and PHP-FPM at the origin, then place Cloudflare in front for proxied DNS and visitor-facing TLS. The reliable sequence is release selection, Composer installation, Magento’s supplied Nginx configuration, origin HTTPS, Cloudflare Full (strict), and origin access controls. Because Adobe changes supported PHP, Nginx, database, search, and Ubuntu combinations between Magento releases, choose the Magento release first and use that release’s requirements rather than copying a version number from another tutorial.

What does a Magento–Nginx–Cloudflare deployment look like?

A visitor connects to Cloudflare over HTTPS. Cloudflare then opens a separate connection to your Ubuntu server, where Nginx terminates or passes through HTTPS and forwards PHP requests to PHP-FPM. Magento stores its files and generated assets on the origin, while Cloudflare provides DNS proxying and the public edge connection.

These are two distinct TLS legs:

  • Visitor to Cloudflare: the certificate visitors see for your public hostname.
  • Cloudflare to origin: a second HTTPS connection to port 443 on your Ubuntu host. Full (strict) validates the origin certificate and hostname.

Cloudflare proxying does not hide an origin that remains discoverable through an unproxied web record, an old DNS entry, or another service on the same address. Plan DNS, certificates, and firewall rules as one design.

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

Which Magento and Ubuntu versions should you choose?

Choose the exact Magento Open Source or Adobe Commerce release before installing Ubuntu packages. Adobe’s system requirements define the supported Linux distributions, PHP minor version, database, search service, and Nginx compatibility for each release. Ubuntu is supported in the documented Linux families, but there is no single PHP or Ubuntu version that is correct for every Magento release.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Decision What to verify Why it matters
Magento release Use the release’s current installation and upgrade documentation. Component support and command-line options change over time.
Ubuntu release Confirm it appears in the selected release’s Linux support list. An otherwise healthy server can be unsupported if the distribution is outside the matrix.
PHP Install the supported minor version as both PHP-FPM and PHP CLI. Nginx needs FPM for web requests, while Composer and bin/magento need the CLI binary.
Database and search Use the database engine and search service versions listed for that release. Search-related installer flags have changed; older Elasticsearch examples may not apply.
TLS Prepare a certificate valid for the origin hostname. Magento requires a valid security certificate for HTTPS; self-signed certificates are not supported by its system requirements.

Record the chosen release, hostname, PHP socket path, database name, search endpoint, and certificate names before you begin. If the server is managed by a hosting provider, check its Nginx and domain controls as well as Adobe’s requirements.

How do you install Nginx, PHP-FPM, Composer, and Magento?

Install the web server and the PHP packages required by your selected release, then create Magento as a Composer project. Adobe’s Nginx procedure uses the Ubuntu www-data web-server group and performs the application installation from the command line.

  1. Install Nginx and the release-specific PHP packages

    Update Ubuntu and install Nginx:

    sudo apt update
    sudo apt -y install nginx

    Replace <version> with the PHP minor version supported by your Magento release:

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    sudo apt install php<version>-fpm php<version>-cli

    Install the other PHP extensions, database client, Composer, and search client components required by that release’s Adobe requirements. Do not assume an extension list from a different Magento version is interchangeable.

  2. Create the Composer project

    From the directory where you keep web applications, run Adobe’s documented metapackage command:

    composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento2

    Composer prompts for Magento repository authentication keys. Use the keys associated with an account authorized to download the selected release. The command creates the project in magento2; choose another directory only if your Nginx root and deployment procedures use that name consistently.

  3. Set ownership and runtime permissions deliberately

    Magento must be able to write its configuration, generated code, cache, media, and static-content paths during installation and deployment. Adobe’s Ubuntu example assigns the web-server group and grants group write access to the required runtime and generated directories. Treat those commands as deployment-specific examples: confirm which account runs Composer and deployments, keep source files as restrictive as possible, and do not make the entire filesystem world-writable.

    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 #2
    Sale
    Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
    • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
    • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
    • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
    • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
    • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
  4. Run the installer from the CLI

    Use bin/magento setup:install with the database credentials, base URL, administrator account, locale, currency, timezone, and search service values required by your release. A secure installation includes options equivalent to:

    --use-secure=1 
    --base-url-secure=https://shop.example.com/ 
    --use-secure-admin=1

    Search engine option names differ between releases, so copy the flags from the selected release’s installation instructions instead of reusing an old Elasticsearch command. Running the installer from the CLI is also Adobe’s recommended fallback when the setup wizard cannot be reached through an Nginx configuration.

After installation, note the Admin URI printed by Magento and keep it out of public documentation. Confirm that the secure base URL uses the same hostname you will proxy through Cloudflare.

How should Nginx be configured for Magento?

Start with Magento’s own nginx.conf.sample, not a generic PHP virtual host. Adobe says the sample contains application routing and security hardening, including rules that prevent execution of harmful uploaded scripts. Replacing it with a minimal location ~ .php$ block can expose files or break rewrites.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Copy the sample into your site configuration workflow

    Adobe’s multi-site guidance recommends copying the sample before editing rather than changing the file inside the Magento installation directly, because a release update may replace it. Keep your customized server configuration under version control and review the sample again after upgrades.

  2. Define the PHP-FPM upstream

    Point Nginx at the Unix socket created by the supported PHP-FPM package. The socket name includes the PHP minor version, so inspect /run/php/ on the host rather than guessing:

    upstream fastcgi_backend {
        server unix:/run/php/php<version>-fpm.sock;
    }

    If Nginx and PHP-FPM use different versions, the site will commonly return gateway errors even though both services are running.

    Rank #3
    Sale
    Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
    • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
    • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
    • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
    • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
    • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
  3. Create and enable the virtual host

    On Ubuntu, place the site file in /etc/nginx/sites-available/ and enable it with a symlink in /etc/nginx/sites-enabled/. The server block must set the public hostname, the Magento root, and the include path to the installation’s sample:

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    set $MAGE_ROOT /var/www/magento2;
    include /var/www/magento2/nginx.conf.sample;

    Add the certificate and key directives required for your origin HTTPS configuration. Keep the sample’s Magento locations and security rules intact; merge SSL settings into the surrounding server block instead of deleting those locations.

  4. Test before reloading

    Run:

    sudo nginx -t
    sudo systemctl reload nginx

    Fix every syntax error before reloading. Check the PHP-FPM service status and socket permissions if Nginx reports an upstream connection failure.

For a new deployment, you can initially serve HTTP while validating the host, but the final design should use HTTPS at the origin before Cloudflare is switched to Full (strict).

Which Cloudflare DNS records should be proxied?

In Cloudflare DNS, proxy the A, AAAA, or CNAME records that serve the Magento storefront and Admin over HTTP or HTTPS. An orange-cloud proxied record sends visitors to Cloudflare first; a DNS-only record resolves directly to the origin address.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Record purpose Recommended status Reason
Storefront hostname Proxied Visitors receive Cloudflare’s edge connection and requests reach the origin through Cloudflare.
Admin hostname, if separate Proxied when compatible Maintains the same edge and origin policy; restrict Admin access separately if required.
Mail, SMTP, IMAP, or other non-HTTP service DNS-only These protocols do not use Cloudflare’s normal HTTP proxy.
Verification or provider-specific records Use the provider’s required status Some services need the record to remain visible as DNS rather than proxied.

Cloudflare’s proxy-status documentation explains the available states. Audit old A and AAAA records, temporary hostnames, and mail-related names for origin leakage. If a hostname is intended to be web traffic, leaving it DNS-only exposes the server address and lets clients bypass Cloudflare.

How do you configure origin HTTPS and Cloudflare Full (strict)?

Install a certificate on Nginx that is unexpired and matches the hostname Cloudflare uses to contact the origin. The certificate may come from a publicly trusted certificate authority or Cloudflare Origin CA. Then select Full (strict), which requires HTTPS on origin port 443 and validates both certificate trust and hostname.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Choose the certificate type

  • Publicly trusted certificate: suitable when the origin may also be reached by administrators, monitoring systems, or other clients that do not trust Cloudflare Origin CA.
  • Cloudflare Origin CA certificate: accepted by Cloudflare for the Cloudflare-to-origin connection, provided it is valid and matches the hostname. It is intended for an origin that Cloudflare fronts.

Install the certificate chain and private key with permissions that allow Nginx to read the key but not ordinary users. Configure the server block to listen on 443, then test with nginx -t and a request to the origin from an authorized test location.

Understand the encryption modes

Mode Origin requirement Operational meaning
Full (strict) HTTPS on port 443 plus an unexpired, hostname-matched certificate from a public CA or Cloudflare Origin CA. Preferred final state because Cloudflare validates the origin identity.
Full HTTPS is available, but the certificate is not fully validated. Encrypts the connection but does not provide the same protection against a fraudulent or mismatched origin certificate.

Use Cloudflare Full (strict) only after origin HTTPS works. A certificate mismatch, expiry, or unavailable HTTPS service can produce Cloudflare error 526. Treat Full as a temporary fallback, not the preferred production setting.

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

Align Magento with the proxy

Set Magento’s secure base URL to the public HTTPS address and enable secure Admin access. Check that Nginx and the application agree about the external scheme when Cloudflare terminates the visitor connection. Test the storefront and Admin independently: a storefront that loads does not prove that Admin redirects, cookies, and static assets are correct.

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

How do you prevent direct-origin bypasses?

Cloudflare proxying is not an origin firewall. Proxied requests arrive from Cloudflare’s published IP ranges, so your host firewall and Nginx access policy must allow those ranges while limiting other inbound web sources where your operations permit it.

  1. Allow Cloudflare’s current ranges

    Obtain the current ranges from Cloudflare’s origin-protection guidance and apply them to ports 80 and 443 as appropriate. Add explicit trusted administrative or monitoring sources only when they are genuinely needed. Keep the list maintained; blocking a changed range can interrupt every visitor.

  2. Reduce alternate paths

    Remove unused DNS records that point to the origin, avoid publishing the server address in web content or mail headers where possible, and restrict direct access by IP at the firewall. If administrators need an emergency direct path, use a controlled allowlist rather than leaving the web ports open to the Internet.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Consider Authenticated Origin Pulls

    Authenticated Origin Pulls (AOP) adds client-certificate authentication to the Cloudflare-to-origin connection. Cloudflare presents a client certificate and Nginx verifies it with ssl_client_certificate and ssl_verify_client. AOP requires Full or Full (strict).

    Best Value
    Sale
    Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
    • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
    • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
    • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
    • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
    • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

    Deploy it in a validation mode first, confirm that normal proxied requests succeed, and only then enforce verification. The global Cloudflare certificate proves that traffic came from Cloudflare’s network but is shared across accounts; a zone-level or per-hostname certificate gives stricter identity control. Plan certificate rotation and a recovery path before turning enforcement on.

What should you test after enabling Cloudflare?

Validate each layer separately, then test the complete visitor path. Use an authorized direct-origin test source; do not weaken the firewall simply to make a test pass.

Check Expected result If it fails
Magento URL Storefront loads at the intended HTTPS hostname. Check DNS record, secure base URL, Nginx server name, and certificate hostname.
Admin URL Admin login page loads and remains on HTTPS. Verify the Admin URI, secure-admin setting, cookies, and proxy/origin scheme handling.
Origin certificate Unexpired certificate matches the hostname Cloudflare uses. Replace the certificate or correct the Nginx certificate chain; error 526 commonly indicates this layer.
Nginx syntax sudo nginx -t succeeds. Fix include paths, duplicate directives, certificate paths, or socket references.
PHP-FPM PHP requests reach the expected Unix socket. Confirm the installed supported PHP version, service status, socket path, and permissions.
Proxy status Web records show proxied status; non-HTTP records remain usable. Correct the individual DNS record instead of changing every record in the zone.
Origin firewall Cloudflare visitors work while unauthorized direct requests are refused. Review current Cloudflare ranges, trusted-source rules, and any exposed alternate hostname.
AOP, if enabled Cloudflare requests succeed with client verification enabled. Return to validation mode, inspect the client certificate configuration, and confirm Full or Full (strict).

Also check product images, static assets, checkout callbacks, cache invalidation, and administrative operations. Mixed-content warnings or redirect loops usually indicate that one layer still believes the canonical scheme is HTTP; compare Magento base URLs, Nginx redirects, and Cloudflare SSL settings rather than adding repeated redirects.

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

Which deployment choices change the procedure?

The core pattern remains the same, but the boundaries differ by environment.

  • Self-managed Ubuntu host: you own package updates, Nginx files, PHP-FPM services, certificates, firewall rules, and Cloudflare DNS.
  • Managed or cloud platform: the provider may control the operating system, Nginx, certificate store, or firewall. Follow its domain and certificate workflow while still checking Adobe’s Magento compatibility matrix.
  • Single hostname: storefront and Admin share one certificate and origin policy.
  • Separate Admin hostname: create and validate a second DNS record and certificate, then ensure Magento’s Admin URL and access controls use that hostname consistently.

Do not copy a configuration from one release or hosting model into another without rechecking the PHP socket, search options, certificate paths, and ownership model.

Frequently Asked Questions

How do I keep Magento email working when Cloudflare is enabled?

Keep MX records and the hostname used by SMTP or IMAP DNS-only unless the mail provider explicitly supports an HTTP proxy. Configure Magento’s mail service to use the mail provider’s documented hostname, not the proxied storefront record, and test password-reset messages separately.

Why does the Magento Admin keep redirecting after I put it behind Cloudflare?

Check that the Admin URL and secure base URL use the same public HTTPS hostname, then look for a second redirect in Nginx or the hosting panel. Clear Magento configuration and browser cookies only after the scheme and hostname are consistent; otherwise the loop will return.

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.

Can I use a Cloudflare Origin CA certificate for direct browser access?

Origin CA certificates are designed for Cloudflare-to-origin encryption. A browser or monitoring client connecting directly to the server may not trust that certificate, so use a publicly trusted certificate when direct access is a supported operational requirement.

Is Authenticated Origin Pulls required for every Magento store?

No. It is an additional origin-authentication control, not a prerequisite for Magento or ordinary Cloudflare proxying. Use it when your threat model justifies client-certificate verification, and stage the change so an incorrect certificate does not lock out all proxied traffic.

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.