I want to redirect all request to nonexistent url (File does not exist: in nginx log) http://example.com/example to index page httt://example.com.

Here is my nginx config:

server {
    listen 80;
    server_name example.com www.example.com;

    access_log off;
    #access_log /srv/www/example.com/logs/example.com-acc main;
    error_log /srv/www/example.com/logs/example.com-err;

    client_max_body_size 256m;

    location / {
        try_files $uri /index.php$is_args$args; # redirect to index
        proxy_redirect off;
        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_read_timeout 300;
        proxy_buffer_size 16k;
        proxy_buffers 32 16k;

    location ~* \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|flv|avi|djvu|mp3|mp4|ogv|3gp|otf)$ {
        root /srv/www/example.com/htdocs/public;

    include vhost.inc.conf;

But I always get "500 internal error" after I trying to follow the wrong link.

In my error log I've got:

19419 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: xxx.xxx.xxx.xxx, server: example.com, request: "GET / HTTP/1.1", host: "example.com"

What's the problem here?

  • What is in vhost.inc.conf? – Michael Hampton Mar 1 '16 at 15:50
  • location ~ /\.git { deny all; } location ~ /\.ht { deny all; } location ~ /\.svn { deny all; } location ^~ /awstatsicons/ { alias /var/www/awstats/icon/; } – powerthrash Mar 1 '16 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.