Halaman

Tampilkan postingan dengan label Nginx. Tampilkan semua postingan
Tampilkan postingan dengan label Nginx. Tampilkan semua postingan

Jumat, 04 Juni 2021

How to fix 404 Not Found Nginx - PHP

I'm working on moving applications from the old server to the new server and have to re-install. At this stage I configure PHP-based applications with related frameworks using Nginx as a web server. The problem that arises is the message Not Found with code 404, when the application runs the index.php file which then calls another file to run the actual process.

 

Next I created a test.php file to detect errors in the application and the tes.php file can run normally (code 200).

Information from curl shows the index.php file Found (302), but controller and action Not Found (404).



Status code HTTP/1.1 302 Found, indicates the requested resource resides temporarily under a different URI

The 404 Not Found message states that the server has not found anything matching the Request-URI.

The results of sudo tail -f /var/log/nginx/error.log and sudo tail -f /var/log/nginx/access.log don't show anything odd. The php files have been processed correctly, but the problem lies most likely in my Nginx configuration which is not suitable for processing php files.

I changed the configuration in the file /etc/nginx/sites-available/myweb.domain.com, which is from

location / {
try_files $uri $uri/ =404;
}
to 

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

Then do sudo service nginx restart and check the result:


As a result, my applications can run as they should and the status becomes HTTP/1.1 200 OK  or request has succeeded.