Ví dụ cấu hình nginx cho LimeSurvey
From LimeSurvey Manual
Ví dụ cấu hình Nginx cho LimeSurvey
Dưới đây là một ví dụ cấu hình để chạy LimeSurvey với nginx và PHP-FPM. Hãy điều chỉnh đường dẫn, tên miền và cài đặt socket/cổng của PHP-FPM cho phù hợp với máy chủ của bạn.
Lưu ý: Đây là một ví dụ cơ bản. Hãy luôn xem xét và điều chỉnh cấu hình này theo yêu cầu bảo mật của riêng bạn trước khi sử dụng trong môi trường production.
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;
}
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;
}
# Deny access to hidden files and sensitive directories
location ~ /\.(?!well-known).* {
deny all;
}
location ~ ^/tmp/runtime/ {
deny all;
}
location ~* /(application|protected|modules|locale|framework|vendor|tests|docs|db|application/config)/ {
deny all;
}
# Disallow uploaded potential executable files in upload directory
location ~* /upload/.*\.(pl|cgi|py|pyc|pyo|phtml|sh|lua|php|php3|php4|php5|php6|pcgi|pcgi3|pcgi4|pcgi5|pcgi6|icn)$ {
return 444;
}
#Disallow direct read user upload files
location ~ ^/upload/surveys/.*/fu_[a-z0-9]*$ {
return 444;
}
location ~* \.(log|sql|htaccess)$ {
deny all;
}
# Allow LimeSurvey to serve uploaded files and assets
location /upload/ {
try_files $uri $uri/ =404;
}
}
Giải thích các chỉ thị chính
fastcgi_pass: Trỏ đến socket hoặc địa chỉ TCP của PHP-FPM xử lý các yêu cầu PHP. Hãy cập nhật giá trị này cho khớp với cấu hình pool PHP-FPM của bạn.try_files: Đảm bảo các URL được định tuyến chính xác qua front controller của LimeSurvey (index.php).client_max_body_size: Tăng dung lượng tải lên tối đa, hữu ích cho các khảo sát có câu hỏi tải lên tệp.- Quy tắc từ chối (Deny): Chặn truy cập web trực tiếp vào các tệp cấu hình, nhật ký và thư mục ứng dụng không bao giờ được phép truy cập công khai.