Report this

What is the reason for this report?

Webserver Nginx download the index file when I want to go to the first page

Posted on September 26, 2020

this is my Nginx config file

    ############# DOMAIN domainname.COM ####################
    server {
    server_name  domainname.com;
    rewrite ^(.*) http://www.domainname.com$1 permanent;
    return 301 $scheme://domainname.name$request_uri;
    }
    server {
    # Basic Domain
    server_name www.domainname.com;
    root /home/www/domainname;
    access_log  /var/log/nginx-domainname-access.log;
    error_log   /var/log/nginx-domainname-error.log;
    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
    # rewrite ^(.+)/index.html$ $1 permanent;
    ## REDIRECT domainname.com/index(.php) to domainname.com/
    if ($request_uri ~ ^(.*/)index(?:\.php)?$) {
    return 301 $1;
    }
    # OR USE :
    ## REDIRECT domainname.com/index(.html) to domainname.com/
    if ($request_uri ~ ^(.*/)index(?:\.html)?$) {
    return 301 $1;
    }
    ## REDIRECT domainname.com/index.html to domainname.com/index
    #if ($request_uri ~ ^(.+)\.html$) {
    #    return 301  $1;
    #}
    
    # To remove a slash at the end:
    rewrite ^/(.*)/$ /$1 permanent;
    
    #try_files $uri $uri/index.html =404;
    #try_files $uri $uri/ /index.php?q=$uri&$args;
    error_page 404 /404.html;

    location / {
    # URLs to attempt, including pretty ones.
    try_files   $uri $uri/ /index.php?$query_string;
    index index.html index.php index.py;
    autoindex on;
    }
    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
        rewrite     ^/(.+)/$ /$1 permanent;
    }
 # cache Media: images, icons, video, audio, HTC
  location ~* \.(jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
  expires 30d;
  add_header Cache-Control "public";
  }
  # cache.appcache, your document html and data
  location ~* \.(manifest|appcache|html?|xml|json)$ {
  expires -1;
  # access_log logs/static.log; # I don't usually include a static log
  }
  location ~* \.(css|js)$ {
   expires 7d;
  }
  # Feed
  location ~* \.(rss|atom)$ {
  expires 1h;
  add_header Cache-Control "public";
  }                                                  
  }
  
server {
   server_name ~^(www\.)(?<subdomain>.+).domainname.com$ ;
   root /home/www/domainname/$subdomain;
}
server {
   server_name ~^(?<subdomain>.+).domainname.com$ ;
   root /home/www/domainname/$subdomain;
}

But Nginx download the index file when I want to go to the first page

then I want to know about “location /” code segment

and I want to know why this occurred

Meanwhile, I had a 403 Forbidden error message before

My used Os is WordPress

please see the code and write me the correct one

I installed WHMCS on a subfolder and I want to know about that

please edit the code to get access to my installed WHMCS on the subfolder too.

thanks ahead and much appreciated

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.