One of the most common and confusing situations when managing a website is encountering a 403 Forbidden or 404 Not Found error when accessing a domain. Many website owners immediately suspect a problem with domain name resolution, but the real cause is often not DNS, but rather server, site configuration, or even permission settings. To quickly restore access and avoid prolonged downtime, it's crucial to understand: is the 403 or 404 error caused by DNS resolution or a server configuration error?
Why are 403 and 404 errors often mistaken for resolution problems? When a 403 or 404 error occurs, most people assume "the website is inaccessible = a domain name resolution error." However, DNS's function is simply to resolve domain names into correct IP addresses; it doesn't determine whether you can access the page, nor does it return a 403 or 404 error.
In other words: DNS errors cause domain names to be inaccessible or unable to connect to the server; 403/404 are HTTP status codes returned by the server. This means that if you've seen a 403 or 404 error, the DNS is usually working correctly.
So what happens when DNS has a problem?
DNS resolution errors typically manifest as follows:
- Unable to access the domain name, displaying the message "Server not found / DNS_PROBE_FINISHED_NXDOMAIN"
- pinging the domain name returns no IP address at all
- dig fails to find the A record
- The browser directly displays "Unable to connect to the server"
Typical prompts include:
DNS address could not be found.
or:
Non-existent domain
Note: DNS will not return 403 or 404. Therefore, if you see a 403/404, you can rule out DNS as the cause in about 80% of cases.
How to determine if a 403/404 error is a server problem or a site configuration problem?
I. Access shows 403? Focus on checking permissions and server policies.
A 403 Forbidden error means the server refuses access to this resource. This is usually related to permissions and directory access policies.
Common causes of 403 errors:
1. Incorrect permissions in the website root directory.
For example, Apache or Nginx may not have permission to read directory files.
In Linux, you can check directory permissions:
ls -l /var/www/html
If the owner is incorrect, try changing it:
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
(Different system users may be nginx, httpd, www)
2. Configure Nginx and Apache to block access to directories
For example, Nginx:
location / {
deny all;
}
Or the index page is not set:
index index.php index.html;
A 403 error will also occur if there is no index file.
3. Firewall/WAF is blocking the request.
For example:
- Firewall rules are blocking access.
- The server's internal firewall is filtering by UA, IP, or Referer.
- Regional access is denied (common on Japanese servers).
You can test this by temporarily disabling the WAF.
4. URL rewriting or path permission errors.
For example, WordPress is missing .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
The lack of rules may also lead to access being blocked.
II. Entry Displaying a 404 Error? Focus on Checking URL Routing, Files, and URL Rewriting
A 404 Not Found error means: the server received the request but could not find the corresponding file or route. DNS will not cause a file not found error; this must be a server-level error.
Common Causes of 404 Errors:
1. File does not exist or the path is incorrect.
For example, when accessing:
https://example.com/about.html
But the document is actually located in:
/var/www/html/pages/about.html
Inconsistent paths naturally result in a 404 error.
2. Incorrect configuration of the website directory root path.
Nginx Example:
root /var/www/html/public;
If the actual entry point of the project is not public, it may cause all paths to return a 404 error.
3. URL Rewriting Configuration Errors
For example, frameworks such as Laravel, ThinkPHP, and WordPress rely on rewrite rules:
Nginx Example:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Missing rules will cause all routes to return a 404 error.
4. Internal routing errors (backend framework)
Common issues in frameworks include: missing controllers, unregistered routes, and inconsistent API version paths.
For example, inconsistent case sensitivity in paths in PHP programs can easily trigger a 404 error.
Practical troubleshooting: How to determine step-by-step whether the problem is caused by DNS or the server?
Step 1: Use `dig` or `nslookup` to confirm that the DNS is working correctly.
dig yourdomain.com
If the IP address is returned, the DNS is functioning correctly.
Step 2: Ping the domain name to confirm whether it resolves to the server.
ping yourdomain.com
If the ping result shows the IP address, but the website reports a 403/404 error, then the DNS is 100% working correctly.
Step 3: Use curl to check the server's returned status code.
curl -I https://yourdomain.com
Output example:
HTTP/1.1 403 Forbidden
or:
HTTP/1.1 404 Not Found
This still indicates that the server received the request, and the DNS is fine.
Step 4: Directly access the server IP
Access using a browser:
http://server IP/
Possible results:
1. IP access also results in 403/404 errors
→ Server configuration error (root directory, permissions, virtual host configuration)
2. IP access is normal, but domain access results in 403/404 errors
→ Incorrect domain binding (incorrect Nginx server_name setting)
Example:
server {
server_name example.com www.example.com;
root /var/www/html;
}
If `server_name` does not match a domain name, the default site will be used, resulting in a 404 error.
Step 5: Check the server error log
The most crucial step!
Nginx Error Log:
/var/log/nginx/error.log
Apache Error Log:
/var/log/apache2/error.log
Logs can almost always tell you the reason, for example:
- Insufficient permissions → Permission denied
- File does not exist → No such file or directory
- Route error → rewrite failed
When accessing a domain name results in a 403 Forbidden or 404 Not Found error, in most cases it's not related to DNS. These two status codes are returned by the server, meaning the browser has successfully connected to the server.
The core principle for determining if it's a DNS problem: Seeing 403/404 = DNS is normal; DNS error = domain name cannot be accessed, IP cannot be resolved
To solve the problem, focus on checking the website's root directory configuration, file existence, URL rewriting rules, permission settings, server_name domain binding, program routing, or internal paths. By following the diagnostic process provided in this article step by step, you can almost always find the cause.
CN
EN