x

บทหลัก

  1. Get started
  2. Workspace
  3. Editor
  4. Question types
  5. Share
  6. Results
  7. Configuration
  8. Installation and updates
  9. Profile and personal settings
  10. Account and billing
  11. FAQs
  12. Development
 Actions

ตัวอย่างการกำหนดค่า nginx สำหรับ LimeSurvey

From LimeSurvey Manual
This page applies to the LimeSurvey Community Edition only. Show the manual for the Community Edition


ตัวอย่างการกำหนดค่า Nginx สำหรับ LimeSurvey

ด้านล่างนี้เป็นตัวอย่างการกำหนดค่าสำหรับการใช้งาน LimeSurvey ร่วมกับ nginx และ PHP-FPM โปรดปรับเส้นทาง ชื่อโดเมน และการตั้งค่าซ็อกเก็ต/พอร์ตของ 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-FPM หรือที่อยู่ TCP ที่ใช้รับคำขอ PHP โปรดอัปเดตให้ตรงกับการกำหนดค่า PHP-FPM pool ของคุณ
  • try_files: ช่วยให้ URL ถูกส่งต่อผ่าน front controller ของ LimeSurvey (index.php) อย่างถูกต้อง
  • client_max_body_size: เพิ่มขนาดการอัปโหลดสูงสุด ซึ่งมีประโยชน์สำหรับแบบสำรวจที่มีคำถามประเภทอัปโหลดไฟล์
  • กฎการปฏิเสธ (Deny rules): บล็อกการเข้าถึงไฟล์การกำหนดค่า บันทึก (log) และไดเรกทอรีของแอปพลิเคชันโดยตรงผ่านเว็บ ซึ่งไม่ควรเปิดให้เข้าถึงได้โดยสาธารณะ nginx จะตรวจสอบ location แบบนิพจน์ปรกตื ตามลำดับที่ปรากฏ และใช้รายการแรกที่ตรงกัน โปรดวางกฎการปฏิเสธไว้เหนือ location ของ PHP มิฉะนั้นไฟล์ PHP ในไดเรกทอรีเหล่านี้จะถูกเรียกใช้งานแทนที่จะถูกปฏิเสธ
  • การติดตั้งในไดเรกทอรีย่อย (Installation in a subdirectory): ตัวอย่างนี้สมมติว่า LimeSurvey ติดตั้งอยู่ใน document root หากคุณติดตั้งในไดเรกทอรีย่อย ให้เพิ่มไดเรกทอรีย่อยนั้นลงในพาธของกฎการปฏิเสธ เช่น location ^~ /limesurvey/vendor/
หน้านี้อาจแปลด้วยเครื่องและอาจมีข้อผิดพลาด ดูต้นฉบับภาษาอังกฤษ · ปรับปรุงคำแปลนี้