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

LimeSurvey nginx 示例配置

From LimeSurvey Manual
This page applies to the LimeSurvey Community Edition only. Show the manual for the Community Edition
本页面可能为机器翻译,可能包含错误。 查看英文原文 · 改进此翻译
This page is a translated version of the page LimeSurvey nginx example configuration and the translation is 100% complete.


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:提高最大上传大小,适用于包含文件上传问题的调查问卷。
  • 拒绝规则:阻止通过网络直接访问配置文件、日志以及不应公开访问的应用程序目录。nginx 会按照正规表达式 location 出现的顺序进行检查,并采用第一个匹配项。请将拒绝规则放在 PHP location 之前,否则这些目录中的 PHP 文件会被执行,而不是被拒绝访问。
  • 安装在子目录中:本示例假定 LimeSurvey 安装在文档根目录中。如果您将其安装在子目录中,请将该子目录添加到拒绝规则的路径中,例如 location ^~ /limesurvey/vendor/。