Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This was really annoying and now i see when it happens. If <ip>/NAME exist in /var/www (/var/www/NAME) nginx will give me a redirect to (note the slash and lack of url) which is annoying and just wrong. If the url ends with a / it will check the index and serve index.html

How do i either make it give me an error page or add a / to the end of it?

server {

    listen   80; ## listen for ipv4
    listen   [::]:80 default ipv6only=on; ## listen for ipv6

    server_name  _;

    access_log  /var/log/nginx/localhost.access.log;
    root   /var/www;

    location / {
        root   /var/www;
        index  index.php index.html index.htm;

    location /doc {
        root   /usr/share;
        autoindex on;
        deny all;

    location /images {
        root   /usr/share;
        autoindex on;

share|improve this question
Is there any include directive in your main configuration file? – quanta Sep 27 '11 at 5:39

server_name_in_redirect off; will tell nginx to use the request's Host: header instead of the first server_name argument when generating redirects.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.