LimeSurvey nginx उदाहरण कॉन्फ़िगरेशन
From LimeSurvey Manual
LimeSurvey के लिए Nginx कॉन्फ़िगरेशन उदाहरण
नीचे nginx और PHP-FPM के साथ LimeSurvey चलाने के लिए एक उदाहरण कॉन्फ़िगरेशन दिया गया है। पाथ, डोमेन नाम और PHP-FPM सॉकेट/पोर्ट सेटिंग को अपने सर्वर सेटअप के अनुसार बदलें।
नोट: यह एक बुनियादी उदाहरण है। इसे प्रोडक्शन में उपयोग करने से पहले हमेशा अपनी सुरक्षा आवश्यकताओं के अनुसार जाँचें और उसमें आवश्यक बदलाव करें।
server {
listen 80;
server_name survey.example.com;
# Redirect all HTTP traffic to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name survey.example.com;
root /var/www/limesurvey;
index index.php;
# SSL certificates
ssl_certificate /etc/ssl/certs/survey.example.com.crt;
ssl_certificate_key /etc/ssl/private/survey.example.com.key;
# Recommended SSL settings
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
client_max_body_size 100M;
access_log /var/log/nginx/limesurvey_access.log;
error_log /var/log/nginx/limesurvey_error.log;
location / {
index index.html index.php;
try_files $uri $uri/ /index.php?$args;
}
# Deny access to directories that are only used on the server
# ^~ gives these locations priority over the PHP location below, so PHP files in them are never executed
location ^~ /application/ { deny all; }
location ^~ /vendor/ { deny all; }
location ^~ /docs/ { deny all; }
location ^~ /locale/ { deny all; }
location ^~ /modules/ { deny all; }
location ^~ /tmp/runtime/ { deny all; }
location ^~ /tests/ { deny all; }
# Uploaded files: never execute scripts, never deliver files uploaded by participants directly
location ^~ /upload/ {
location ~* \.(php\d?|phtml|pl|py|pyc|pyo|cgi|pcgi\d?|sh|lua|icn)$ {
deny all;
}
location ~ ^/upload/surveys/.*/fu_[a-z0-9_]*$ {
deny all;
}
try_files $uri =404;
}
# Regular expression locations are checked in order and the first match wins,
# so all deny rules below must stay above the PHP location
# Deny access to hidden files and directories, except .well-known
location ~ /\.(?!well-known) {
deny all;
}
# Deny access to the internal directories of the KCFinder file manager
location ~ ^/assets/packages/kcfinder/(conf|core|doc|integration|lang|lib|tpl)/ {
deny all;
}
# Deny access to development, build and debug files in the LimeSurvey root directory
location ~ ^/(setdebug\.php|open-api-gen\.php|composer\.(json|lock)|package\.json|yarn\.lock|gulpfile\.js|phpunit\.xml|psalm(-\w+)?\.xml|phpci\.yml|phpcs\.ruleset\.xml|publiccode\.yml|manifest\.yml|CONTRIBUTING\.md|README\.md|SECURITY\.md)$ {
deny all;
}
location ~* \.(log|sql|htaccess)$ {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
मुख्य डायरेक्टिव की व्याख्या
fastcgi_pass: PHP अनुरोधों को संभालने वाले PHP-FPM सॉकेट या TCP पते को दर्शाता है। इसे अपने PHP-FPM पूल कॉन्फ़िगरेशन के अनुसार अपडेट करें।try_files: यह सुनिश्चित करता है कि URL, LimeSurvey के फ्रंट कंट्रोलर (index.php) के माध्यम से सही ढंग से रूट हों।client_max_body_size: अधिकतम अपलोड आकार बढ़ाता है, जो फ़ाइल-अपलोड प्रश्नों वाले सर्वेक्षणों के लिए उपयोगी है।- Deny rules: कॉन्फ़िगरेशन फ़ाइलों, लॉग और एप्लिकेशन डायरेक्टरी तक सीधी वेब पहुँच को रोकते हैं, जिन्हें कभी भी सार्वजनिक रूप से उपलब्ध नहीं होना चाहिए। nginx नियमित अभिव्यक्ति वाले लोकेशन को उसी क्रम में जाँचता है जिसमें वे लिखे गए हैं, और पहला मेल खाने वाला नियम लागू होता है। Deny नियमों को PHP लोकेशन से ऊपर रखें, अन्यथा इन डायरेक्टरी में मौजूद PHP फ़ाइलें अस्वीकृत होने के बजाय निष्पादित हो जाएँगी।
- सबडायरेक्टरी में इंस्टॉलेशन: उदाहरण मानता है कि LimeSurvey को डॉक्यूमेंट रूट में इंस्टॉल किया गया है। यदि आप इसे किसी सबडायरेक्टरी में इंस्टॉल करते हैं, तो सबडायरेक्टरी को deny नियमों के पाथ में जोड़ें, उदाहरण के लिए
location ^~ /limesurvey/vendor/।