Welcome! Log In Create A New Profile

Advanced

Nginx download the index file and 404 Not Found when I want to go to the first page

Posted by redscience 
Nginx download the index file and 404 Not Found when I want to go to the first page
September 28, 2020 01:58PM
Hello,
this is my Nginx config file for Domain:

----------------------------------------------------------------------------------------
############# DOMAIN domainname.COM ####################
server {
server_name domainname.com www.domainname.com;
rewrite ^(.*) http://domainname.com$1 permanent;
return 301 $scheme://domainname.name$request_uri;
}
server {
listen 80;

# Basic Domain
server_name domainname.com www.domainname.com;
root /home/www/domainname;
index index.php index.html index.htm index.py;
autoindex on;
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 / {
root /home/www/domainname;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}
# 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";
}
location ~ /\.ht {
deny all;
}
}
server {
server_name ~^(www\.)(?<subdomain>.+).domainname.com$ ;
root /home/www/domainname/$subdomain;
}
server {
server_name ~^(?<subdomain>.+).domainname.com$ ;
root /home/www/domainname/$subdomain;
}

----------------------------------------------------------------------------------------



And this is my configuration for the nginx.conf Global config file

----------------------------------------------------------------------------------------

###############################################################
#usually equal to number of CPUs you have. run command "grep processor /proc/cpuinfo | wc -l" to find it
worker_processes auto;
worker_cpu_affinity auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}
http {
include mime.types;

include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-available/*;
include /etc/nginx/sites-enabled/*;
include /etc/nginx/fastcgi_params;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
client_max_body_size 13m;
keepalive_timeout 65;
index index.php index.html index.htm;
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types application/javascript application/rss+xml application/vnd.ms-fontobject application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/opentype font/otf font/ttf image/svg+xml image/x-icon text/css text/javascript text/plain text/xml;

upstream php-fpm {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name localhost;
error_log /var/log/nginx-error.log warn;
location / {
root /home/www;
#this line tells NGINX to look for index.php, then index.html, then index.htm
index index.php index.html index.htm;
#proxy_connect_timeout 300s;
#proxy_read_timeout 300s;
#proxy_pass php-fpm;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/www;
#root /var/www/unixmen;
}

location ~ \.php$ {
include /etc/nginx/fastcgi_params;
#fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param HTTP_PROXY "";
}

}
}

----------------------------------------------------------------------------------------

In this code, Firstly, Nginx downloaded the index file when I want to go to the first page

But now I get 404 Not Found error message

I want to know why this happened

My used CMS is WordPress

My OS is Slackware

My PHP version is 7.4.10

If you need any other details, please don't be hesitate to tell me about that

I am waiting for the correct one

In the addition, I installed WHMCS on a subfolder and I want to know about the code segment that can help me to access to WHMCS without a problem

thanks ahead



Edited 1 time(s). Last edit at 09/28/2020 01:59PM by redscience.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 126
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready