2017-01-20 9 views
14

मैं nginx पुन: कॉन्फ़िगर किया है, लेकिन मैं इसे निम्नलिखित config का उपयोग कर पुन: प्रारंभ नहीं प्राप्त कर सकते हैं:nginx: [emerg] "सर्वर" निर्देश यहाँ अनुमति नहीं है

conf:

server { 
listen 80; 
server_name www.example.com; 
return 301 $scheme://example.com$request_uri; 
} 


server { 
listen 80; 
server_name example.com; 

access_log /var/log/nginx/access.log; 
error_log /var/log/nginx/error.log; 

location /robots.txt { 
    alias /path/to/robots.txt; 
    access_log off; 
    log_not_found off; 
} 

location = /favicon.ico { access_log off; log_not_found off; } 

location/{ 
    proxy_pass_header Server; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
     proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Scheme $scheme; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_connect_timeout 30; 
    proxy_read_timeout 30; 
    proxy_pass http://127.0.0.1:8000; 
} 

location /static { 
    expires 1M; 
    alias /path/to/staticfiles; 
} 
} 

sudo nginx -c conf -t चलाने के बाद विन्यास निम्नलिखित त्रुटि दिखाई है मैं समझ नहीं क्या वास्तव में समस्या

nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-available/config:1 
nginx: configuration file /etc/nginx/sites-available/config test failed 

उत्तर

28

एक nginx विन्यास फाइल नहीं है यही कारण है परीक्षण करने के लिए। यह nginx कॉन्फ़िगरेशन फ़ाइल का है।

events { 
    ... 
} 
http { 
    ... 
    server { 
     ... 
    } 
} 

server ब्लॉक एक http ब्लॉक के भीतर संलग्न है: जैसे

nginx विन्यास फाइल (आमतौर पर nginx.conf कहा जाता है) पर गौर करेंगे।

अक्सर अतिरिक्त टुकड़ों को खींचने के लिए include निर्देशों का उपयोग करके कॉन्फ़िगरेशन को कई फ़ाइलों में वितरित किया जाता है (उदाहरण के लिए sites-enabled निर्देशिका से)।

पूर्ण कॉन्फ़िगरेशन फ़ाइल का परीक्षण करने के लिए sudo nginx -t का उपयोग करें, जो nginx.conf पर शुरू होता है और include निर्देश का उपयोग करके अतिरिक्त टुकड़ों में खींचता है। अधिक के लिए this document देखें।

संबंधित मुद्दे