I have a site that uses subdirectories and currently only works when the trailing slash is added to the URL ("http://www.domain.com/dir/"). When there is no trailing slash, I get "unable to connect at server domain.com:8080" (8080 is the listening port Nginx is set up for).

I've tried adding the rewrite suggested here (and here), but it results in the "cannot connect" error for the entire virtual host.

Is there another way to add the trailing slash that I could try? Or, is there a way I can configure it to see the URL as a directory (and thus, look for the index file), regardless of the presence of the trailing slash?


I too tried but i dint find proper solution. But you can try forceful passing to backend. If www.domain.com/dir comes it should go to backend

location /dir {

        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

              proxy_set_header Host $host;

  • 1
    The key that I want/need is for it to go to www.domain.com/dir**/** when www.domain.com/dir is typed in. This works on my local server, which uses port 80, but not my live one, which is using port 8080. – Shauna Jul 29 '11 at 12:40

Not sure if I'm getting you wrong, but linking a file to the sites-enabled nginx directory with the following content replaces host.tld/gls with host.tld/gls/ for me if I connect to the former.

server {
    location /gls {
        root   /var/www/;

Your Answer

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

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