Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adammench's avatar

All URL's return 200 header.

Hey,

I'm running Forge on Digital Ocean, and have run into a strange problem. For all my sites, there is never a 404 header returned for them.

For example:

www.example.com/asdfoiudff

returns 200 and loads the homepage index.php. Any query for a page url that is typed into the browser does the same thing.

I think it is possible an nginx issue, as it is happening with newly provisioned sites where I do nothing to the nginx configuration.

0 likes
7 replies
adammench's avatar

I think it is related to this part of my nginx setup for the site (the default forge code):

location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

In the above example, if a request is made for /blahblah, the first location will initially get the request. It will try to find a file called blahblah in the root directory. If it cannot find one, it will follow up by searching for a file called blahblah.html. It will then try to see if there is a directory called blahblah/

Failing all of these attempts, it will redirect to /index.php

This means that any url entered which does not serve a page, will return to index.php

I'm still stuck however, as doing this:

location / {
        try_files $uri $uri/ 
    }

Breaks the site. Any tips please?

memu's avatar

@adammench do you have any route definition in your routes.php file which catches all urls? A catch-all or default route?

adammench's avatar

It's actually not a Laravel project, its a CMS project using Perch. (grabaperch.com).

So I don't have a specific route set up.

bashy's avatar

@adammench I would create a php file with a status header of 404 or something other than 200. See if it picks it up in Nginx (which it will since it forwards all statuses). You can set your own 404 page/response as well in Nginx. Also check the request via cURL to see if there's no a redirect for every status (404).

1 like
adammench's avatar

Thanks @bashy - adding a file with a simple php header to return a 404 header works when testing with cURL:

http://penchant.youi.design/custom.php :
<?php 
header("HTTP/1.0 404 Not Found");

cUrl response:

HTTP/1.1 404 Not Found Server: nginx/1.11.1 Date: Mon, 11 Jul 2016 14:32:36 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive

However, every request still returns a 200. (e.g. http://penchant.youi.design/kljsdlfkjds)

Here is my nginx conf:

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/penchant.youi.design/before/*;

server {
    listen 80;
    listen [::]:80;
    server_name penchant.youi.design;
    root /home/forge/penchant.youi.design/public;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate;
    # ssl_certificate_key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/penchant.youi.design/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/penchant.youi.design-error.log error;

    error_page 404 /404.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/penchant.youi.design/after/*;
bashy's avatar

@adammench Remove this line

error_page 404 /404.php;

I'd also add this line to the php location block (first line within)

try_files $uri =404;
adammench's avatar

Thanks @bashy

Much appreciated. It turns out, this fixed it:

location / {
        # try_files $uri $uri/ /index.php?$query_string;
        try_files $uri $uri/ =404;
}

error_page 404 /404.php;

then running

$ sudo nginx -s reload

for some reason

$ sudo service nginx restart
or
$ sudo service nginx reload

wasn't reloading my configuration.

1 like

Please or to participate in this conversation.