1

I need to create a nginx configuration with redirect, this is my conf:

server {

listen          8080;
server_name     test.example.org;
index           index.php index.html;
return          301 $scheme://test.example.org/dashboard;
location        /dashboard {
    alias           /path/to/files;
    index           index.php index.html;
    }
}

I need redirect test.example.org to test.example.org/dashboard,when i go to test.example.org, my browser get an error "Too many redirects"

  • I'm not familiar with nginx, but shouldn't the values of location and alias be swapped? It makes more sense to me that way... – l0b0 Sep 22 '14 at 11:49
1

Try to put

return          301 $scheme://test.example.org/dashboard;

inside

location / {
}
  • Not work, now the browser returns after 10-20 seconds "test.example.org:8080/dashboard". "8080" is inserted and i have errors – hellb0y77 Sep 22 '14 at 12:43
  • 8080 is the port your server listening (as by your config). So if you see the URL you mentionned, the redirection works as expected. Now you should look where points alias directive and what files are there. By the way I suggest to replace alias by root with full path to files, as alias works sometimes strange. – Artiom Sep 22 '14 at 13:25
  • With 'root' works, but "dashboard" not exists like physical path, and have 404 error – hellb0y77 Sep 22 '14 at 14:21
  • So rename your directory. Honestly I never managed to make alias work for my config. Nothing to do with redirection, but with many locations and rewrites. Try to look in the webserver's log with alias in place. It can give you a clue. – Artiom Sep 22 '14 at 14:58
  • 1
    OK i resolved inserting port_in_redirect off; in nginx.conf. Now have another problem, when i go to test.exanmple.org/dashboard, nginx insert "/dashbord" at the beginning of URL and not find any files: es. "GET /dashboard/modules/notify/module.js HTTP/1.1" 404 199 "test.domain.com/dashboard" – hellb0y77 Sep 22 '14 at 15:54
0

This is how I do it,

location / {

    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args @goto_dashboard;
}

location @goto_dashboard {
    return 301 http://xxx/dashboard;
}

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.