I am facing a 404 error when I access my site directly from IP. The default root directory is /var/www/html
. And I am accessing it through http://<server_public_ip>/folder_name
.
This is my folder structure.
/var/www/html
├── WordPress1/
├── WordPress2/
├── CI_or_Larawel/
├── any_direct_file (.php,.zip or anything else)
Generally the default location directive
location / {
try_files $uri $uri/ =404;
}
should work for all files & folder under the root directory. But its not working. When I access it from the IP http://<server_public_ip>/folder_name
its going to 404.
To resolve this I am forced to create multiple location directive based on sites installed on the root directory. I do not want this. I just wanted it should work whatever site/folder I add under root directory.
My conf file is as follows
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
# I do not want to add location directive for all folders under /var/www/html
# but the default location was not working and it was going to 404. That I would like to change
location /wordpress1 {
try_files $uri $uri/ /wordpress1/index.php?$args;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
#try_files $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# fastcgi_pass 127.0.0.1:9000;
}
location ~ /\.ht {
deny all;
}
}
I just want any file/folder I put under /var/www/html
it should work normally without adding location directive. Thanks in advance