O
O
Olga2019-04-12 02:53:45
Nginx
Olga, 2019-04-12 02:53:45

How to be: nginx, 404 error does not work with /?something?

Site on nginx. Non-existent URLs are given their own 404 error page. So I thought until I saw information about the duplicate of the main page in Ya.Webmaster. The duplicate looks like mysite.ru/?something
How to fix the situation?
For internal pages, the error is handled normally.
PS. Competencies in nginx - "I read the documentation and understand almost everything" ). I worked with the server in the courses. On the current site, another person is in charge of the server, but the level is "at the beginning of the journey."
nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid
events {
worker_connections 768; # Why so many?
# multi_accept on; # Why is it disabled?
}
http {
sendfile on; # Why no data limit?
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65; # Recommended units
types_hash_max_size 2048;
# server_tokens off; # why disabled?
# server_names_hash_bucket_size 64;
# server_name_in_redirect off; # prevents absolute redirects issued by nginx from using the main server name specified by the server_name directive. The off value is the default. So, in this case, it makes no sense
to include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # ref: POODLE - what is it?
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
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 text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; # defines the MIME types for which compression will work. Why is it disabled?
# why not: client_max_body_size 8M;
include /etc/nginx/conf.d/*.conf; #?
include /etc/nginx/sites-enabled/*;
}
Site configuration mysite.ru
server {
listen 443 ssl;
root /somepath;
server_name mysite.ru www.mysite.ru mysite.com;
index index.html;
ssl_certificate /etc/letsencrypt/live/mysite.ru/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.ru/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
error_page 404 /ErrorPages/404.html;
try_files $uri $uri/ =404;
location / {
# try_files $uri $uri/index.html $uri.html =404; # is this a special case of try_files $uri $uri/ =404? Or does it make sense to use both directives?
#try_files $uri $uri/ /index.html?$args; I believe this directive creates duplicates of the main
one #if (!-e $request_filename){
# return 404;
#}
# This is part of the old code. I suggest replacing with try_files $uri $uri/ =404 in the server context;
}
}
server {
listen 80;
server_name mysite.ru www.mysite.ru mysite.com;
return 301 https://$server_name$request_uri;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Olga, 2019-04-13
@Olgavm

Thank you.
Perhaps this line is to blame:
I think to rewrite it:
To get rid of random duplicates, I decided to add rel="canonical" to the page code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question