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.

Consider the following Nginx configuration file (Nginx version 1.2.6 on 64-bit Linux):

location / {
    root html/www.domain.com;
}
location /image/ {
    root html/static.domain.com;
}

Using this configuration, the following requests work as expected:

/index.html

is picked up from the directory html/www.domain.com

/secure/profile.html is picked up from the directory html/www.domain.com

/image/logo.jpeg is picked up from the directory html/static.domain.com

However, the following requests result in errors (understandably):

/index.html;affiliate=msn

/image/logo.jpef~partner=msnbc

What should be the correct Nginx configuration to ignore URL parts such as ;affiliate=msn and ~partner=msnbc?

share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

Something like this

    location / {
        try_files $uri $uri/index.html =404;
    }
    location ~ "(.*)[;~].*" {
        try_files $1 $1/index.html =404;
    }
share|improve this answer
    
Although we had solved the problem before your answer, I really appreciate your taking out the time to answer the question. I am accepting your answer as it is indeed a valid solution to the problem we were facing. The only thing would be to escape the semi-colon as [\;\~]. Without escaping it our Nginx installation would find the configuration file invalid. –  manish.in.java Jan 27 '13 at 12:28
add comment

Have changed the configuration as follows to get the desired behaviour.

location /image/ {
    rewrite ^(/image/.*)[\;\,\~].*$ $1 break;
    root    html/static.domain.com;
}

Please note that semi-colon has to be escaped (\;) since it is a statement delimiter in Nginx configuration files.

share|improve this answer
add comment

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.