2013-08-24 6 views
12

मैं एक साधारण डेमो वेबसाइट के लिए Nginx उपयोग कर रहा हूँ के साथ असंवेदनशील बनाने के लिए, और मैं सिर्फ इस तरह Nginx कॉन्फ़िगर करें:कैसे URL केस Nginx

server { 
    listen   80; 
    server_name  www.abc.com; 

    location/{ 
     index   index.html; 
     root   /home/www.abc.com/; 
    } 
} 

मेरी www.abc.com फ़ोल्डर में, मैं उप-फ़ोल्डर Sub नामित है, और अंदर index.html फ़ाइल है। तो जब मैं www.abc.com/Sub/index.html पर जाने का प्रयास करता हूं, तो यह ठीक काम करता है। अगर मैं www.abc.com/sub/index.html पर जाता हूं, तो यह 404 देता है।

URL में केस-असंवेदनशील के लिए Nginx को कॉन्फ़िगर कैसे करें?

उत्तर

17
server { 
    # Default, you don't need this! 
    #listen   80; 

    server_name  www.abc.com; 

    # Index and root are global configurations for the whole server. 
    index   index.html; 
    root   /home/www.abc.com/; 

    location/{ 
     location ~* ^/sub/ { 
      # The tilde and asterisks ensure that this location will 
      # be matched case insensitive. nginx does not support 
      # setting absolutely everything to be case insensitive. 
      # The reason is easy, it's costly in terms of performance. 
     } 
    } 
} 
+0

वाह कूल, बहुत बहुत धन्यवाद। –

+0

उपर्युक्त समाधान मेरे लिए काम नहीं कर रहा है .. क्या आप कृपया मेरी मदद कर सकते हैं। ~ * केवल स्थिति के लिए काम करता है – Catmandu

+3

मुझे लगता है कि यह सभी यूआरएल * युक्त */sub/(उदाहरण के साथ यह भी मिल जाएगा "example.com/yellow/उप/")। यह 'स्थान ~ * ^/उप /' (देखभाल के साथ) होना चाहिए। –