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

NGINX and Apache can run on the same server when they do not try to bind the same IP address and TCP port. To expose NGINX on port 8080, configure a server block with listen 8080; (or the narrower listen 127.0.0.1:8080;), then move Apache to a different unused endpoint such as 127.0.0.1:8081. If NGINX is the public front end, a more usual arrangement is NGINX on ports 80 and 443 and Apache on a loopback-only port such as 8080, with proxy_pass forwarding requests to it.

The essential rule is simple: one process per address-and-port pair. The rest of the configuration determines which daemon is public, whether NGINX serves files or proxies them, how virtual hosts are selected, and whether redirects and client IP information remain correct.

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

What it means to run both daemons

A listening socket is identified by an IP address and a TCP port. Two independent processes cannot normally claim the same pair. NGINX listening on 0.0.0.0:8080 conflicts with Apache listening on 0.0.0.0:8080, but they can coexist if one uses port 8080 and the other uses 8081, or if they use different addresses such as a public address and loopback.

An omitted address in an NGINX listen directive means all local addresses. Binding to 127.0.0.1 restricts connections to the same host. That distinction matters: a loopback-only Apache backend is not directly reachable from the network, while an NGINX listener on all addresses can accept remote requests if the firewall permits them.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

Choose the layout before editing files

There are two practical designs and one special case. Select the one that matches who should receive traffic first.

Layout Public listener Apache endpoint NGINX role When to use it
NGINX exposed on 8080 NGINX on :8080 Apache on 127.0.0.1:8081 or another free port Serves a site directly or proxies selected paths The requirement explicitly calls for NGINX at port 8080
NGINX front end NGINX on ports 80 and/or 443 Apache on 127.0.0.1:8080 Terminates TLS, serves static files, and reverse-proxies dynamic requests A public website should have one front door while Apache remains private
Independent sites Each daemon owns a different address-and-port pair Apache is directly reachable on its own endpoint Does not proxy Apache Separate applications or a migration where both servers are intentionally public

For a quick test, the first layout is sufficient. For production, the second layout usually reduces exposure: Apache listens only on loopback and NGINX is the sole public entry point. Do not publish both daemons merely because both are installed.

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.

Inspect existing listeners first

Before changing a configuration, record what currently owns ports 80, 443, and 8080. A port that appears free in a configuration file may already be held by a running process or a container.

sudo ss -ltnp
sudo lsof -nP -iTCP:80 -sTCP:LISTEN
sudo lsof -nP -iTCP:443 -sTCP:LISTEN
sudo lsof -nP -iTCP:8080 -sTCP:LISTEN
sudo systemctl status nginx apache2

On systems that name the service httpd rather than apache2, use that service name in status and reload commands. Write down the address as well as the port. For example, 127.0.0.1:8080 and 192.0.2.10:8080 are different bindings, while a wildcard listener such as 0.0.0.0:8080 generally covers every IPv4 address on the host.

Layout A: NGINX on 8080 and Apache on 8081

This arrangement leaves NGINX at the requested port and moves Apache to a separate loopback endpoint. The examples use Ubuntu or Debian file locations; other distributions may use different paths, but the directives are the same.

1. Select the Apache address and port

Use an unused pair, such as 127.0.0.1:8081. Loopback is preferable when Apache should be reachable only by NGINX or local administration. If another local service already owns 8081, choose another free port and use it consistently in every file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

2. Change Apache’s Listen directive

On Ubuntu, Apache’s port declarations are normally in /etc/apache2/ports.conf. Replace the old public declaration with the selected endpoint. For a loopback-only backend:

Listen 127.0.0.1:8081

The Listen directive specifies the port and, optionally, the IP address Apache should accept. If the file contains several Listen lines, remove or change the ones that would collide with another daemon. Keep any additional ports that are deliberately used for separate sites.

3. Match every Apache virtual host

Changing Listen alone is not enough. Apache virtual hosts still naming the old endpoint can fail validation or select the wrong site. Edit the relevant files under /etc/apache2/sites-available/ so their bindings match:

<VirtualHost 127.0.0.1:8081>
    ServerName example.com
    DocumentRoot /var/www/example

    <Directory /var/www/example>
        Require all granted
    </Directory>
</VirtualHost>

Use the real host name and document root for the application. If a site is not meant to answer on this endpoint, disable its old virtual-host file rather than leaving a stale binding. On Ubuntu or Debian, enable the intended site with sudo a2ensite site-name.conf when necessary.

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

4. Configure NGINX to listen on 8080

Create or edit the appropriate NGINX server block. This example serves files directly:

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

    index index.html index.htm;
}

listen 8080; accepts connections on port 8080 on the host’s local addresses. To restrict NGINX to local clients, use listen 127.0.0.1:8080; instead. If remote users should reach the site, retain a public address binding and allow TCP 8080 in the host and cloud firewalls.

Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

5. Validate before reloading

Test both configurations before asking the service manager to reload them:

sudo apachectl configtest
sudo nginx -t

Apache should report a successful syntax check, and NGINX should report that the configuration test is successful. Fix every error before reloading. Then apply the changes without stopping the daemons:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo systemctl reload apache2
sudo systemctl reload nginx

If your distribution uses httpd, substitute sudo systemctl reload httpd. A reload keeps existing workers serving current connections while new workers use the new configuration; a restart is more disruptive and should be reserved for cases where a reload cannot apply the change.

6. Verify the exact endpoint

Confirm the sockets after reloading, then request the URL including its non-default port:

sudo ss -ltnp | grep -E ':(8080|8081)b'
curl -i http://127.0.0.1:8080/
curl -i http://127.0.0.1:8081/

The first request should reach NGINX and the second should reach Apache directly from the server. If Apache is loopback-only, a curl request made from another machine to port 8081 should fail by design. For a public NGINX listener, test from a separate network and use http://example.com:8080/; browsers omit the port only for their default HTTP and HTTPS ports.

Layout B: NGINX as the public reverse proxy

When NGINX should own the front door, put it on port 80 for HTTP and, if TLS is enabled, port 443 for HTTPS. Apache listens on a private loopback port such as 8080. NGINX then forwards requests to Apache instead of exposing Apache directly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

1. Put Apache on loopback 8080

In Ubuntu, set the port in /etc/apache2/ports.conf:

Listen 127.0.0.1:8080

Change each corresponding Apache virtual host to <VirtualHost 127.0.0.1:8080>. Apache will still see the request after NGINX forwards it, but the network cannot connect to that backend port unless access is local to the server.

2. Add the NGINX proxy server block

Use a location block containing proxy_pass:

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;
    }
}

The upstream port in proxy_pass must exactly match Apache’s address and port. The Host header lets Apache and the application select the intended virtual host. The other headers preserve the original client address and whether the browser used HTTP or HTTPS. Configure the application to trust forwarded headers only from your NGINX proxy; blindly trusting client-supplied forwarding headers can make logs and access controls unreliable.

3. Add HTTPS without exposing Apache

If NGINX terminates TLS, the HTTPS server block listens on 443 and proxies to the same loopback backend. The backend connection can remain HTTP on the private host unless you have a specific requirement for encryption between local processes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate     /path/to/fullchain.pem;
    ssl_certificate_key /path/to/private.key;

    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;
    }
}

Use the certificate paths and TLS settings appropriate for your installation. If port 80 redirects to HTTPS, make that redirect in the NGINX HTTP server block so the browser sees the public host and port rather than Apache’s private endpoint.

4. Account for redirects and absolute URLs

An application may generate a redirect using its own view of the request. Without the forwarded host and scheme, it can redirect users to 127.0.0.1:8080, to an internal port, or repeatedly from HTTPS to HTTP. Verify the application’s base URL and its trusted-proxy setting. When a proxy emits or rewrites backend Location headers, review Apache’s reverse-proxy behavior and use the appropriate ProxyPassReverse arrangement if Apache itself is proxying another service. The objective is that every public redirect points to the public scheme, host, and port.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How NGINX selects the server block

NGINX first selects a default server for the address and port that accepted the connection. It then compares the request’s Host header with each server_name on that listener. A request to example.com:8080 can therefore select a different block from a request to an unrecognised host on the same port.

Give each site a unique name and avoid accidental duplicate default_server declarations on one address-and-port pair. If no name matches, the default block answers. A browser using an IP address sends that IP in the Host header, so it may intentionally reach the default rather than the named 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.

Address binding, firewall, and exposure decisions

  • All-address binding: listen 8080; can expose NGINX on every local address. Use it only when remote access is intended and filter the port with host and cloud firewall rules.
  • Loopback binding: listen 127.0.0.1:8080; accepts local connections only. This is appropriate for a backend or a development-only service.
  • IPv6: Check whether your distribution adds an IPv6 listener such as [::]:8080. An IPv4 rule does not automatically describe every IPv6 binding, and an IPv6 wildcard can expose a service unexpectedly.
  • Firewall consistency: Opening TCP 8080 in a firewall does not help a service bound only to loopback. Conversely, a public listener may still be unreachable if the host or cloud firewall blocks the port.
  • Least exposure: If NGINX proxies Apache, do not open Apache’s backend port externally. Restrict it to loopback or a private interface used only by the proxy.

Distribution and file-layout differences

Ubuntu and Debian commonly separate Apache’s global port declarations in /etc/apache2/ports.conf and virtual hosts in /etc/apache2/sites-available/, with enabled links under /etc/apache2/sites-enabled/. Other distributions may keep Apache configuration under /etc/httpd/, and NGINX server blocks may live in a distribution-specific directory. Do not copy a path blindly; locate the active configuration with the service’s package documentation or its startup command, then apply the same Listen, <VirtualHost>, listen, and proxy_pass relationships.

The service names also vary. Ubuntu commonly uses apache2 and nginx; Red Hat-family systems commonly use httpd and nginx. The configuration test and reload must target the daemon actually installed on the host.

Troubleshoot the common failures

Symptom Likely cause Checks and fix
“Address already in use” Another process owns the same address-and-port pair, or duplicate listen directives exist. Run ss -ltnp and identify the owner. Change one Listen/listen endpoint or stop the conflicting service. Do not solve it by adding another identical binding.
NGINX works on localhost but not remotely NGINX is intentionally bound to loopback, or a firewall blocks TCP 8080. Check the exact address in ss. If remote access is required, bind to the appropriate interface and allow the port in both host and cloud firewalls.
NGINX returns 502 Bad Gateway Apache is stopped, listening elsewhere, or inaccessible at the address in proxy_pass. Check Apache status, run ss -ltnp, and curl the backend locally. Make the Apache Listen, virtual-host binding, and NGINX proxy_pass value identical.
Apache redirects to 8081 or another private port The application constructs URLs from the backend request, or proxy headers and redirect rewriting are incomplete. Pass Host and X-Forwarded-Proto, set the application’s public base URL, and inspect redirect Location headers. If Apache is itself proxying, configure the required reverse redirect handling.
The wrong NGINX site appears The request matched the default server, a duplicate default exists, or the Host header does not match server_name. Review all server blocks on that port, keep one deliberate default, and test with the intended host name using curl.
Apache fails after the port change A virtual host still names the old endpoint, or the new port is already occupied. Run apachectl configtest, search enabled site files for the old binding, update every matching <VirtualHost>, and verify the new socket is free.
Requests reach Apache directly The backend is bound to a public address or its firewall rule permits external traffic. Bind Apache to 127.0.0.1 or a private interface and remove public firewall access to the backend port.

Operational checklist

  • Record current owners of ports 80, 443, and 8080 before editing.
  • Choose one address-and-port pair for every daemon and document whether it is public or loopback-only.
  • Keep Apache’s Listen directive and every matching <VirtualHost> declaration in agreement.
  • Keep NGINX’s listen, server_name, and any proxy_pass destination internally consistent.
  • Use unique server names and one intentional default server per listener.
  • Preserve the original host, client address, and scheme when proxying.
  • Run both configuration tests before each reload and inspect service status afterward.
  • Test locally and from the intended client network, using the explicit port when it is not 80 or 443.
  • Keep Apache’s backend port closed to external clients when NGINX is the public front end.

Which configuration should you use?

Use NGINX on :8080 and Apache on 127.0.0.1:8081 when port 8080 is the required public endpoint or when you are testing NGINX independently. Use NGINX on 80/443 with Apache on 127.0.0.1:8080 when NGINX should terminate TLS, enforce public host names, serve static content, and proxy application requests. In either case, the configuration succeeds only when the bindings are distinct, all virtual-host declarations match the selected ports, and each daemon is reloaded only after its syntax test passes.

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.

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