Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
VGSources
Blog

How to Stop Gunicorn and Nginx Serving the Default Django Project

A practical troubleshooting guide for making Nginx route the correct hostname and Gunicorn start the intended Django project, with systemd examples, socket and TCP checks, and failure fixes.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If Nginx shows its welcome page or Gunicorn loads a different Django site, trace the request through both routing boundaries: Nginx must select the correct server {} block, and that block must forward to a Gunicorn process started with the intended project, virtual environment, and working directory. Inspect the loaded configuration, remove the competing default site, correct proxy_pass, repair the systemd unit, then test with the real domain in the HTTP Host header.

Why the default project appears

There are two separate selection decisions. Treating them as one problem often leads to changing Django settings when the request never reached that Django process, or changing Nginx when the proxy is correctly forwarding to the wrong Gunicorn service.

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.

Nginx chooses a virtual server before it proxies anything

Nginx first uses the connection’s listen address and port, then compares the HTTP Host header with the server_name values in the server blocks listening there. If the host does not match, Nginx sends the request to that port’s default server. When no server block is explicitly marked default_server, the first server loaded for the address and port becomes the default.

That behavior explains a common pattern: the domain is configured in a file you edited, but Nginx still serves its distribution welcome page. The intended file may not be included, its symlink may be missing, the request may use a different host name, or the packaged default server may be winning the match.

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

Gunicorn can start a different Django application

After Nginx selects a server, proxy_pass sends the request to a Unix socket or TCP port. The Gunicorn process at that endpoint has its own application selection. Its module name, systemd WorkingDirectory, virtual environment, optional --pythonpath, and DJANGO_SETTINGS_MODULE determine which Django project starts.

The normal invocation is gunicorn myproject.wsgi, run from the directory containing that project’s manage.py. A correct Nginx configuration cannot fix a systemd unit that starts otherproject.wsgi or runs from a directory where imports resolve to another package.

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

Static files can create a third misleading result

Nginx commonly serves CSS, JavaScript, and uploaded files directly with a root or an explicit static location, while proxying dynamic requests to Gunicorn. If the selected server block has the wrong document root, a static request can look like a default site even though dynamic requests are reaching Django. Always identify which server block handles the request and whether the path is served locally or proxied.

Identify which layer is wrong

What you see Most likely boundary First checks
Nginx welcome page or a distribution default page Nginx virtual-server selection server_name, listen port, HTTP Host, enabled-site links, and the loaded configuration
Your domain displays another Django project Gunicorn application selection systemd ExecStart, WorkingDirectory, virtualenv path, WSGI module, and DJANGO_SETTINGS_MODULE
502 Bad Gateway Proxy-to-Gunicorn connection Gunicorn status, socket or port, proxy_pass, and socket permissions
HTML is correct but CSS or JavaScript is from a default site Nginx static-file handling Selected server’s root, static location, and whether another server block handled the asset request
Domain works but the server IP shows a default page Host-name mismatch The IP request’s Host header and whether the IP is deliberately listed in server_name

Inspect the configuration Nginx and systemd actually loaded

Do not rely on the file you think is active. Distribution layouts usually separate available site files from enabled symbolic links, and Nginx may include additional files from its main configuration.

  1. Print the complete parsed Nginx configuration, including included files:
    sudo nginx -T
    Search the output for every listen, server_name, default_server, root, and proxy_pass. This reveals duplicate server blocks and the order in which they are loaded.
  2. List enabled site links and inspect where they point. On layouts that use the conventional directories, run:
    ls -l /etc/nginx/sites-enabled/
    Confirm the intended site file is linked and that the packaged default is not still competing on the same port.
  3. Read the service definition that starts Gunicorn:
    sudo systemctl cat gunicorn-project.service
    If the service has a template name, substitute its actual unit name. Also check overrides with:
    sudo systemctl status gunicorn-project.service
  4. Record the endpoint in both places. Write down the socket path or TCP address in Gunicorn’s start command, then compare it character-for-character with Nginx’s proxy_pass. A one-character path difference creates a 502 or sends traffic to another service.

When several Gunicorn units exist, compare their unit names, process IDs, working directories, and bind arguments. A healthy process is not necessarily the process your selected Nginx server uses.

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

Make the intended Nginx server block win

Declare every hostname users actually send

Put the production domain and any deliberate www alias in the same server_name directive. For example:

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

    location /static/ {
        alias /srv/example/static/;
    }

    location / {
        proxy_pass http://unix:/run/gunicorn-example.sock;
        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;
    }
}

Replace the domain, static directory, and socket with the values used by your deployment. The important points are that the block listens on the public port, names the requested host, and forwards dynamic requests to the intended endpoint. Keep static handling separate so a document root from an unrelated site cannot answer those paths.

Disable the packaged default site when it competes

If the distribution’s default site listens on the same address and port, disable its enabled link or remove that site from the active include set. On systems using the conventional layout, a typical operation is:

sudo unlink /etc/nginx/sites-enabled/default

Use the actual link shown by your system; do not delete a file blindly. Keeping an available copy is harmless, but an enabled default server can capture unmatched hosts and obscure configuration errors.

Use an intentional catch-all only when you need one

Some administrators retain a catch-all server to reject unknown hosts or redirect them. Make that choice explicit rather than allowing whichever file loads first to become the default:

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.
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 80 default_server;
    server_name _;
    return 444;
}

The status and behavior are policy choices. A catch-all should not proxy to your Django application accidentally. If you need IP access for administration or testing, create a deliberate rule for it; otherwise test with the production domain.

Check that the file is included

A correctly written file has no effect if the main Nginx configuration does not include it. nginx -T is the authoritative check because it prints the parsed result, not merely a directory listing. If your distribution does not use sites-enabled, follow the include paths shown at the top of that output.

Point proxy_pass at the right Gunicorn endpoint

Unix socket arrangement

A Unix socket is a filesystem endpoint, often used when Nginx and Gunicorn run on the same machine. The socket path in Nginx must exactly match the bind path used by Gunicorn. Nginx’s worker user also needs permission to connect to it.

# Gunicorn argument
--bind unix:/run/gunicorn-example.sock

# Matching Nginx directive
proxy_pass http://unix:/run/gunicorn-example.sock;

If the service creates the socket in a runtime directory, check that the directory exists after boot and that its ownership and mode permit Nginx access. A running Gunicorn process with an inaccessible socket still produces a 502.

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

Loopback TCP arrangement

With TCP, Gunicorn binds to a local address and port, and Nginx proxies to that exact address:

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
# Gunicorn argument
--bind 127.0.0.1:8001

# Matching Nginx directive
proxy_pass http://127.0.0.1:8001;

Do not change the port in only one configuration. If multiple Django projects use TCP, assign and document a distinct port for each service.

Consideration Unix socket Loopback TCP
Endpoint Filesystem path such as /run/gunicorn-example.sock Address and port such as 127.0.0.1:8001
Typical failure Wrong path, missing runtime directory, or Nginx permission denial Port mismatch, service not listening, or another process using the port
What to compare Gunicorn bind path, Nginx proxy_pass, owner, group, and mode Gunicorn bind address and port, Nginx target, and listening process
Isolation test Use a local request through the Unix socket Use a local request to the loopback port

Correct the Gunicorn systemd unit

Open the unit and verify all fields that determine application identity. A representative service looks like this:

[Unit]
Description=Gunicorn for the example Django project
After=network.target

[Service]
User=django
Group=www-data
WorkingDirectory=/srv/example
ExecStart=/srv/example/venv/bin/gunicorn example.wsgi 
    --bind unix:/run/gunicorn-example.sock

[Install]
WantedBy=multi-user.target

The values are examples, not universal paths. Your WorkingDirectory should contain the intended project’s manage.py, and the executable in ExecStart should belong to that project’s virtual environment. The WSGI module must identify the same project’s package. If settings are not selected by the WSGI module, set the intended DJANGO_SETTINGS_MODULE explicitly in the unit’s environment.

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

Check for subtle project mix-ups

  • Two projects may have similar package names. Confirm the absolute working directory and inspect the module path from that environment.
  • An old unit may still be enabled and listening on the endpoint you expect the new unit to use.
  • A --pythonpath option can make imports resolve outside the working directory. Remove it or correct it when it points at the wrong source tree.
  • Running Gunicorn manually from a shell can hide a broken systemd environment. Compare the manual command with ExecStart, user, environment, and working directory.

After editing a unit, ask systemd to reread it, restart the service, and inspect the result:

sudo systemctl daemon-reload
sudo systemctl restart gunicorn-example.service
sudo systemctl status gunicorn-example.service
sudo journalctl -u gunicorn-example.service -n 100 --no-pager

Use the actual unit name. A successful restart only proves the process launched; the logs and endpoint test establish that it launched the intended Django project.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Validate configuration before testing in a browser

  1. Validate Nginx syntax and included files:
    sudo nginx -t
    Do not reload until it reports a successful test.
  2. Reload Nginx so the corrected server block becomes active:
    sudo systemctl reload nginx
  3. Inspect Gunicorn’s resolved settings when a service starts an unexpected application. From the appropriate virtual environment, gunicorn --print-config displays resolved configuration, while gunicorn --check-config validates application configuration. Run these with the same module, working directory, and environment used by systemd.
  4. Test the public route with an explicit host header. From the server or another machine, use:
    curl -i -H 'Host: example.com' http://127.0.0.1/
    This distinguishes domain routing from a browser cache and proves which virtual host handles that host value.
  5. Test the application endpoint directly. For a TCP bind:
    curl -i http://127.0.0.1:8001/
    For a Unix socket, use a curl build that supports Unix sockets:
    curl --unix-socket /run/gunicorn-example.sock -i http://localhost/
  6. Compare response headers, status, and HTML between the direct Gunicorn request and the Nginx request. If direct Gunicorn is wrong, fix systemd or Django. If direct Gunicorn is right but Nginx is wrong, fix virtual-server selection, proxying, or static handling.

Fix the common failure branches

The Nginx welcome page remains

Run nginx -T and find the server block that returns the welcome page. Confirm the request’s host and port, then check whether the intended file is enabled and included. Remove or replace the competing default link, add the real domain and www alias to server_name, test syntax, and reload. If you intentionally kept a catch-all, verify that it is not the only matching block.

The wrong Django project appears

Bypass Nginx and query the Gunicorn socket or port. If the wrong project is returned directly, inspect ExecStart, WorkingDirectory, the virtualenv executable, WSGI module, --pythonpath, and DJANGO_SETTINGS_MODULE. Check for a second unit or an old process using the same endpoint. Restart the corrected unit after a daemon reload.

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.

Nginx returns 502 Bad Gateway

First establish that Gunicorn is running. Then compare the bind argument with proxy_pass exactly. For sockets, inspect existence and permissions; for TCP, verify the listening address and port. Nginx’s error log usually identifies whether the failure is “no such file,” “permission denied,” or “connection refused,” which tells you whether to repair the path, ownership, or process.

Only static files come from the default site

Use the loaded configuration to find the selected server’s root, alias, and location rules. Ensure the static path points to the intended project’s collected files and that another server block is not matching the asset host. Dynamic proxying and static serving are independent; fixing one does not automatically fix the other.

The domain works but the IP address does not

A request made to an IP normally carries that IP as its Host value, which may not match a domain-only server_name. Nginx then uses the port’s default server. Include the IP deliberately only if that access path is required; otherwise use the domain and an explicit host-header test when diagnosing the production route.

Compare deployment arrangements before changing them

If you are deciding between two working layouts, compare the complete path rather than choosing a socket or port in isolation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Question Evidence to record
Which endpoint is used? Unix socket path or loopback TCP address and port in both Gunicorn and Nginx
Who owns the process and endpoint? systemd User/Group, socket owner and mode, and Nginx worker permissions
Which project starts? Unit name, WorkingDirectory, virtualenv executable, WSGI module, and settings module
Which request reaches it? Listen address, port, server_name, aliases, default server, and actual HTTP Host
Who serves static files? Nginx root/alias and location rules, separate from the Gunicorn route

The arrangement with fewer ambiguous defaults is easier to operate. Give each project a clearly named unit, a unique endpoint, an explicit server name, and a documented static directory.

Prevent the problem from returning

  • Keep one authoritative systemd unit per Django project and give the unit, socket, and service logs matching names.
  • Use absolute paths for the working directory, virtualenv executable, WSGI module, and socket or bind address.
  • Keep the packaged default site disabled unless it is an intentional catch-all.
  • After every configuration change, run nginx -t, reload Nginx, and check the relevant service status and logs.
  • Document every production hostname, including whether www and direct IP access are supported.
  • Include a direct Gunicorn endpoint test and a domain request with an explicit Host header in deployment checks.

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