A
A
Andrew Lays2015-08-07 23:54:29
Nginx
Andrew Lays, 2015-08-07 23:54:29

How to make a normal 404 error?

There is nginx with the following configs:

server {
  listen 80;

  server_name bety.ml *.bety.ml;

  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl spdy;

  server_name bety.ml *.bety.ml;

  ssl_session_cache shared:SSL:10m;
  ssl_session_timeout	 5m;
  ssl_prefer_server_ciphers	 on;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_certificate /etc/nginx/ssl/bety.ml_bundle.crt;
  ssl_certificate_key /etc/nginx/ssl/bety.ml.key;
        ssl_trusted_certificate /etc/nginx/ssl/ca-certs.pem;
  ssl_dhparam /etc/nginx/ssl/dhparam.pem;
  ssl_ciphers kEECDH+AES128:kEECDH:kEDH:-3DES:kRSA+AES128:kEDH+3DES:DES-CBC3-SHA:!RC4:!aNULL:!eNULL:!MD5:!EXPORT:!LOW:!SEED:!CAMELLIA:!IDEA:!PSK:!SRP:!SSLv2;
  ssl_stapling on;
  ssl_stapling_verify on;

  resolver 8.8.8.8 8.8.4.4 valid=300s;
  resolver_timeout 5s;

        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
  add_header Content-Security-Policy-Report-Only "default-src https:; script-src https: 'unsafe-eval' 'unsafe-inline'; style-src https: 'unsafe-inline'; img-src https: data:; font-src https: data:; report-uri /csp-report";

  root /var/bety/$subdomain;
  index index.php;

  set $subdomain "";

  if ($host ~* ^([a-z0-9-\.]+)\.bety.ml$)
  {
    set $subdomain $1;
  }

  if ($subdomain = "www")
  {
    return 301 $scheme://bety.ml$request_uri;
  }

  if ($subdomain = "")
  {
    set $subdomain "www";
  }

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

  location /
  {
    try_files $uri $uri/ /index.php;
  }

  location ~ \.php$
  {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

If you type example.com/some_page.php in the address bar, it will return a 404 error, everything is as it should, and if you type, say, example.com/some_directory, it will return the main page, i.e. the same thing as making a request for example. com/index.php , or typing example.com/some_file.html , example.com/some_pic.gif , example.com/some_book.pdf , again returns the main page, but not a 404.
What's wrong with the configs?
PS: https://bety.ml/

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TyzhSysAdmin, 2015-08-08
@Andrew_Lays

location /
  {
    index index.php;
  }

nginx.org/ru/docs/http/ngx_http_core_module.html#t...

P
Puma Thailand, 2015-08-08
@opium

So in your config it says so if there is no file then go to the php index
try_files $uri $uri/ /index.php;
It is logical to pass all the parameters to it depending on the cms
For wordpress, let's say
try_files $uri $uri/ /index.php?q=$uri&$args;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question