Answer the question
In order to leave comments, you need to log in
How to correctly register configs for 404 errors in nginx?
Hello, the problem is this: when you call a non-existent page, for example , for mysite.ru/wrongpage
some reason, the main page opens.
configs are:
server{
listen 80;
server_name www.mysite.ru;
rewrite ^ http://mysite.ru$request_uri? permanent; #301 redirect
}
server {
listen 80;
server_name mysite.ru;
root /home/user/mysite;
location / {
index index.htm index.html index.php;
try_files $uri /index.html;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
}
location = /index.html {
if ($request_uri = /index.html) {
rewrite ^ http://mysite.ru? permanent;#301 redirect
}
}
error_log /var/log/nginx/mysite.error.log;
access_log /var/log/nginx/mysite.access.log;
}
Answer the question
In order to leave comments, you need to log in
What is the purpose of your /index.html in try_Files?
Tries to find $uri and if it doesn't find it redirects to /index.html.
This is the try_Files syntax:
try_files file ...uri;
error_page 400 404 /404.html;
location = /404.html {
root /home/address
}
well, that's how it is for me.
outside of this:
location / {
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question