Response 404 not found when requesting a suffix suffix .js in the browser (openresty, server: cloudflare)
1. Reference:In Laravle 6, simulate a route requesting a resource file, and the data is fetched from the database . Request 200 in the local environment. as shown in Figure 1
2. In the production environment, the response is 404 not found (openresty, server: cloudflare). as shown in Figure 2
3. Check the Nginx request log to make sure that the request has arrived at the Nginx server. as shown in Figure 3
4. Print in the entry file index.php, confirm that the php file is not executed.
5. Suspect is related to the configuration of nginx in the production environment, and configure this paragraph to add in nginx of the local environment
server {
location ~* .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
expires 30d;
add_header Cache-Control "public";
}
}
6. In the local environment, the PHP file can be executed (inconsistent with the production environment), but the response status code is 404 (consistent with the production environment). as shown in Figure 4
7. Edit the configuration of nginx, add location ^~ /static/theme, which means matching any address starting with /static/theme, after matching, stop searching for regularity, and use this one. After location ~* .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
location ^~ /static/theme {
try_files $uri /index.php =404;
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass php_farm;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
expires 30d;
add_header Cache-Control "public";
}
8. In the local environment, the PHP file can be executed, and the response status code is 200, which is in line with expectations. as shown in Figure 5
9. Then, after the production environment is also processed in this way, the response is 200. as shown in Figure 6





