0

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

  • I don't see any issue in your configuration why things wouldn't work properly. Please add clear repro steps, what request you are making, what is the expected result and what is the actual result. – Tero Kilkanen Nov 13 '22 at 09:44
  • I am simply entering the IP/foldername. If you want I can share you the Server name & necessary details privately. – Sanjay Goswami Nov 13 '22 at 13:03
  • Please add the exact details into the question. What is the exact request and response. – Tero Kilkanen Nov 13 '22 at 13:15
  • I have updated my question – Sanjay Goswami Nov 13 '22 at 18:30
  • The details are still quite not exact. There is no detailed information what 404 you receive. However, to me your target state looks impossible. You want to support different CMS, but do not want to apply per-CMS configurations. You need to have proper front controller configuration for each CMS, and that requires per path `try_files` directive. – Tero Kilkanen Nov 13 '22 at 18:45

0 Answers0