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

I installed ispconfig/nginx on ubuntu 12.10 following "perfect server" here: http://www.howtoforge.com/forums/showthread.php?t=61141

I need to apply rewrite rules to nginx from a .haccess file with these contents:

RewriteRule ^(.)/(.)-video_(.*).html$ musicvideo.php?vid=$3

RewriteRule ^([^/]*)-video_(.*).html$ watch.php?vid=$2

i used an online converter and got this output:

location / {
rewrite ^/(.*)/(.*)-video_(.*).html$ /musicvideo.php?vid=$3;

rewrite ^/([^/]*)-video_(.*).html$ /watch.php?vid=$2;
}

Then I put the code in ./sites-available/default under server block and restarted nginx but I am getting error:

duplicate location "/" in /etc/nginx/sites-enabled/default:133
nginx: configuration file /etc/nginx/nginx.conf test failed

and If I put my rewrite rules within the existing Location:

location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
rewrite ^/(.*)/(.*)-video_(.*).html$ /musicvideo.php?vid=$3;

rewrite ^/([^/]*)-video_(.*).html$ /watch.php?vid=$2;
}

then nothing happens! could someone please point out to me what I am doing wrong?

share|improve this question

1 Answer 1

The order of directives matters in nginx. Try moving the rewrite rules up to the top of the / location.

share|improve this answer

Your Answer

 
discard

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.