Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Run Nginx on Port 8080 Alongside Apache

Put Nginx on port 8080 without stopping Apache by assigning distinct address-and-port bindings, updating Apache's listeners and virtual hosts, and proxying to the correct backend when needed.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes, Nginx and Apache can run on the same server when they do not claim the same address-and-port pair. To put Nginx on port 8080, add listen 8080; to its server block. Move Apache to another unused endpoint, such as 127.0.0.1:8081, and change every Apache virtual host to match. If Nginx is the public front end, use proxy_pass to send requests to Apache’s private port.

The important distinction is between a port number and a complete socket address. Two daemons cannot both bind 0.0.0.0:8080, but they can use different ports, or in some designs the same numeric port on different local IP addresses. The configurations below use separate ports because that is the portable, least-surprising arrangement.

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.

How the port assignment works

A listening socket is identified by an IP address and TCP port. A normal Nginx declaration such as listen 8080; means Nginx accepts connections on port 8080 on all local addresses unless another setting narrows the bind. listen 127.0.0.1:8080; restricts it to loopback, so only programs on the same machine can connect.

Apache uses its own Listen directive and virtual-host bindings. On Ubuntu, the main port setting is in /etc/apache2/ports.conf; the enabled site files are under /etc/apache2/sites-available/ and are commonly enabled through the corresponding sites-enabled directory. A port change is incomplete if a virtual host still names the old endpoint.

#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.

For the layout in this guide, Nginx owns 8080 and Apache owns 8081. If Apache is only a backend, binding it to loopback prevents clients from bypassing Nginx. If both services must be independently reachable, use a routable address for Apache instead, while still choosing a port that no other process owns.

Choose the layout before editing files

Decide which daemon should receive client connections, whether Apache should be reachable from the network, and where TLS will terminate. These choices determine the correct listen, Listen, and proxy settings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Layout Public endpoint Backend endpoint Static files TLS termination When to choose it
Nginx on 8080, Apache on 8081 Nginx at :8080 Apache at 127.0.0.1:8081 or another selected address Nginx, Apache, or both Usually Nginx if HTTPS is added elsewhere You specifically need Nginx to accept traffic on 8080.
Nginx reverse proxy on 8080 Nginx at :8080 Apache at 127.0.0.1:8081 Nginx can serve files; Apache handles dynamic requests Nginx can terminate TLS before proxying You want one public entry point with Apache kept private.
Nginx front end on 80/443 Nginx at 80 and/or 443 Apache at 127.0.0.1:8080 or another private port Nginx commonly serves static files Nginx normally terminates TLS You want standard web ports and Apache as an application backend.
Independent services Nginx and Apache each have their own address and port Apache is not proxied by Nginx Each service serves its own site Configured separately The applications are unrelated and must remain operationally separate.

The rest of the procedure demonstrates the first two rows: Nginx listens on 8080, while Apache listens on 8081. A later section shows the common alternative where Nginx owns 80/443 and Apache owns a private 8080 port.

Inventory listeners and choose an unused endpoint

Do not edit either configuration until you know what currently owns ports 80, 443, and 8080. Record the address as well as the port. A service bound only to loopback is different from one bound to every interface.

  1. Check the service status using your operating system’s service manager. Confirm whether Nginx, Apache, or another daemon is active.
  2. Inspect listening TCP sockets with the distribution’s socket or process tools. On systems that provide it, ss -ltnp shows listening addresses, ports, and owning processes; use elevated privileges if process names are hidden.
  3. Select an Apache port that is not already occupied. This guide uses 127.0.0.1:8081, which keeps Apache local and leaves Nginx as the only network-facing service.
  4. Write down the final plan before changing files: Nginx on :8080, Apache on 127.0.0.1:8081, and Nginx proxying to the latter if Apache serves the application.

If another process already owns 8081, choose a different free port and substitute that number consistently in Apache’s Listen, every matching VirtualHost, and Nginx’s proxy_pass.

Move Apache to 127.0.0.1:8081

Update the global Listen directive

On Ubuntu, open /etc/apache2/ports.conf with administrative privileges. Replace the existing Apache HTTP listener with:

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

If the file contains more than one Listen line, decide deliberately whether each one is required. Leaving an old listener in place can make Apache continue accepting traffic on an endpoint you intended to retire. Do not add a second copy of the same address-and-port pair.

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

Update every enabled virtual host

Find each enabled site whose opening tag still refers to the old port. Change it to the same address and port used above:

<VirtualHost 127.0.0.1:8081>
    ServerName example.com
    DocumentRoot /var/www/example
    # existing directives for this site
</VirtualHost>

The ServerName shown is an example hostname for the configuration; use the hostname that belongs to your site. If you have several Apache sites, give each its own ServerName and, where needed, additional ServerAlias values, but keep their bindings on the selected Apache endpoint.

Do not change an Apache virtual host to 8081 while leaving ports.conf on another port. Apache must have both a global listener and a matching virtual-host address. Conversely, changing ports.conf alone can leave requests routed to an unexpected default virtual host.

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.

Reload Apache safely

  1. Run Apache’s installed configuration-test command before reloading. On Ubuntu this is commonly apache2ctl configtest; use the equivalent supplied by your distribution if the command name differs.
  2. Reload Apache through the host service manager rather than stopping it unnecessarily. A reload applies valid configuration while preserving existing connections where the service supports that behavior.
  3. Inspect the effective sockets again. Apache should now show 127.0.0.1:8081 and should no longer own the endpoint you assigned to Nginx.

If the test reports an address conflict, another Apache include may still declare the old or duplicate listener. Search all included configuration files and remove or change the stale declaration before attempting another reload.

Configure Nginx to listen on port 8080

Expose Nginx on all local addresses

Create or edit the Nginx server block for the site that should receive traffic on 8080:

server {
    listen 8080;
    server_name example.com;
    root /var/www/example;
}

The unqualified listen 8080; form accepts connections on all local addresses for that port. A client must include :8080 in the URL unless DNS, a load balancer, or another front end maps a standard port to it.

Bind Nginx only to loopback when it is internal

If another local service is the only client, narrow the listener:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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)
server {
    listen 127.0.0.1:8080;
    server_name example.com;
    root /var/www/example;
}

This prevents remote hosts from connecting directly to Nginx on 8080. It also means a browser on another machine cannot reach that endpoint, even if the host firewall allows TCP 8080. Choose the scope intentionally rather than treating loopback as a troubleshooting workaround.

Test and reload Nginx

  1. Run nginx -t. The test must report a valid configuration before you reload.
  2. Reload Nginx through the service manager, for example with the service’s reload action. If your distribution uses a different manager or unit name, use its equivalent.
  3. Confirm that Nginx now owns the selected 8080 address and that Apache owns only its selected backend endpoint.
  4. Request the exact URL, including :8080 when the listener is externally exposed. Test locally first, then from an intended remote network if the service is public.

If the Nginx configuration contains several server blocks on 8080, make sure only the intended one is the default for that address and port, or explicitly mark the desired block as the default.

Proxy Nginx requests to Apache

Serving independent sites requires no proxy. If Apache generates the application response while Nginx is the public entry point, put a proxy_pass inside a Nginx location block. With Nginx public on 8080 and Apache private on 8081, use:

server {
    listen 8080;
    server_name example.com;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:8081;
    }
}

The upstream port in proxy_pass must exactly match Apache’s listening address and port. The forwarding headers preserve the original host, client address, proxy chain, and scheme for applications that understand them. Configure the application to trust these headers only from your Nginx proxy; accepting arbitrary client-supplied forwarding headers can produce incorrect URLs or security decisions.

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

Nginx can serve static assets directly and proxy only dynamic paths. For example, a separate location for a known asset directory can use Nginx’s root, while the broader location proxies to Apache. Keep the path rules unambiguous so a request is not unexpectedly handled by the wrong block.

Alternative: Nginx on 80/443 and Apache on private 8080

The title requirement is Nginx on 8080, but many deployments actually need Nginx on standard public ports and Apache behind it. In that design, Apache can listen on 127.0.0.1:8080, while Nginx owns 80 and 443:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:8080;
    }
}

Here Apache’s Listen and virtual hosts must use 127.0.0.1:8080, not 8081. Nginx is the only daemon exposed to clients, and the backend port should not be opened in a host or cloud firewall. Add an analogous HTTPS server block when TLS terminates at Nginx, and pass the original scheme so Apache or its application can generate HTTPS links and redirects.

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

If Apache itself performs additional proxying, review redirect headers and absolute URLs. Apache’s reverse-proxy behavior commonly requires ProxyPassReverse when it is the proxy layer. In the Nginx-to-Apache arrangement above, inspect the response Location header whenever a redirect reveals an internal port.

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

Names, default servers, and virtual-host selection

A port assignment alone does not select a site. Nginx first chooses a default server for the requested listen address and port, then compares the request’s Host header with each server_name. A request to an IP address, a missing host, or an unmatched hostname can therefore land in a different server block than expected.

  • Give each Nginx site a distinct server_name.
  • Avoid declaring more than one default_server for the same address and port.
  • Use the same public hostname in the proxy’s Host header when Apache or the application relies on it.
  • When testing, send a request with the intended hostname and the configured port rather than relying only on an IP address.

Apache performs a similar virtual-host choice after accepting a connection. Every Apache virtual host that should answer on 8081 must use the matching binding, and its names must correspond to the hostnames Nginx forwards.

Address exposure, firewalls, and TLS decisions

Binding Nginx to all addresses makes TCP 8080 reachable wherever routing and firewall rules permit it. Open that port only when remote clients require it. Binding to loopback is safer for an internal hop because packets never arrive from the network interface.

Check both layers of filtering when a remote request fails: the host firewall and any cloud or upstream firewall. A service listening on 127.0.0.1 will remain unreachable remotely even if both firewalls allow 8080; a service listening on all addresses can still be unreachable when either firewall blocks the port.

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

Choose one clear TLS termination point. If Nginx terminates HTTPS, proxy the request to Apache over the intended local HTTP endpoint and pass X-Forwarded-Proto. If Apache terminates TLS instead, Nginx must forward to the appropriate secure upstream and the application must be configured consistently. Do not let redirects alternate between the public URL and an internal port.

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

Troubleshooting by symptom

“Address already in use”

Another process already owns the exact address-and-port pair, or a duplicate listener exists in one of the service’s included files. Inspect active sockets, identify the owner, and either stop the unnecessary service or select a free endpoint. Changing only the displayed server name will not resolve a bind conflict.

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.

The site works locally but not remotely

Check the Nginx bind first. If it is 127.0.0.1:8080, remote access is intentionally impossible; use an all-address listener only when exposure is required. If Nginx is bound publicly, check host and cloud firewall rules for TCP 8080 and verify that routing reaches the correct machine.

Nginx returns 502 Bad Gateway

Confirm that Apache is running, listening on the same address and port written in proxy_pass, and reachable from the Nginx process. A common mismatch is Apache on 127.0.0.1:8081 while Nginx still proxies to 127.0.0.1:8080. Correct the number, reload after a successful nginx -t, and test again.

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.

Apache redirects to 8081 or another private port

Inspect the application’s base URL and Apache’s generated redirect headers. Ensure Nginx sends the original Host and X-Forwarded-Proto, and that the application is configured to trust the proxy. If another proxy layer is involved, review its reverse-proxy redirect rewriting as well.

The wrong virtual host appears

Check which server block is the default for the address and port, remove duplicate default_server declarations, and verify that the request’s Host value matches the intended server_name. Then check Apache’s matching virtual-host names and bindings.

Configuration reload fails

Run the relevant configuration test and read the first reported error, which is often the cause of later messages. Typical causes include a misspelled directive, an unclosed block, a duplicate listener, or a virtual host that still references a removed port. Fix the file, test again, and reload only after validation succeeds.

Verification checklist

  • Nginx has exactly the intended listen address and port.
  • Apache’s Listen directive and every relevant VirtualHost use the selected Apache endpoint.
  • No unrelated process owns either endpoint.
  • nginx -t succeeds, and Apache’s configuration test succeeds.
  • Both services were reloaded through their service manager after validation.
  • A local request reaches the intended Nginx server block.
  • If proxying, proxy_pass points to the exact Apache socket and forwarding headers are present.
  • Remote testing matches the exposure decision: all-address binding plus permitted firewall rules for public access, or loopback binding for an internal-only service.
  • Redirects and generated links use the public hostname and scheme rather than the backend port.

What a correct final arrangement looks like

For the specific requirement “Nginx on port 8080 alongside Apache,” the simplest valid result is Nginx listening on :8080, Apache listening on 127.0.0.1:8081, and no other daemon using those same sockets. Nginx may serve the site directly or proxy requests to Apache. The port numbers themselves are not the integration mechanism; the deliberate bindings, matching virtual hosts, proxy target, and forwarding headers are.

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

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
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.