Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Here is the error we have when loading nginx on ubuntu 12.04 server:

nginx: [emerg] invalid number of arguments in "location" directive in /opt/nginx/conf/nginx.conf:58

What we are trying to do is to append a string to the end of uri entered. For example, if mysite.com/abcd or mysite.com/abcd/ are entered, nginx should rewrite them to mysite.com/abcd/auth/signin

Here is what we have in nginx.conf:

location {
          rewrite "/[a-zA-Z]\w{1,9}/" /$1/auth/signin last;
          rewrite "/[a-zA-Z]\w{1,9}" /$1/auth/signin last;

What's wrong with the location block above and how we should name the location block? Thanks for the help.


Here is server block in nginx.conf:

 server {
        listen 80;
        server_name mysite.com;
        root /var/www/;
        passenger_enabled on;
        rails_env production;
        passenger_base_uri /nbhy;

share|improve this question

1 Answer 1

up vote 1 down vote accepted

A location block needs a uri. So, you may want this:

location / {
    rewrite "/[a-zA-Z]\w{1,9}/" /$1/auth/signin last;
    rewrite "/[a-zA-Z]\w{1,9}" /$1/auth/signin last;

Or, if you don't want to apply these rewrites to a certain path, just remove the location part altogether. I.e.

rewrite "/[a-zA-Z]\w{1,9}/" /$1/auth/signin last;
rewrite "/[a-zA-Z]\w{1,9}" /$1/auth/signin last;
share|improve this answer
What's the uri for the location block? Does it mean anything? –  user938363 Jun 9 '13 at 23:03
Now the nginx error disappeared. But there is an 500 error with mysite.com/abcd. There is no change on the url displayed in browser. Firebug did not show what's the uri it rewrote. –  user938363 Jun 9 '13 at 23:12

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.