Welcome! Log In Create A New Profile

Advanced

Moodle config running, but needs optimization

Posted by Oneota 
Moodle config running, but needs optimization
December 27, 2011 12:47PM
We migrated our Moodle server from Apache+PHP to nginx+php-fpm, and it's working, but the week prior to Christmas was final exam time at the high school and the server just fell to its knees several times a day. What was happening, from what I could tell, was that nginx was trying to connect to a php process, and none were available. We continually upped the number of PHP processes that were allowed to spawn, but eventually we were using almost all available RAM and the system just slowed to a crawl.
So, I'm thinking we probably have some room for configuration optimization, both in our nginx config and in the php-fpm implementation. Can anyone offer some assistance?

Here's our nginx.conf:

-------------------------------- BEGIN nginx.conf
#user nobody;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/log/nginx/nginx.pid;
events {
worker_connections 4096;
}


http {

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log;
client_max_body_size 70M;
#tcp_nopush on;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 30;
tcp_nodelay on;
gzip on;
send_timeout 10;
## FastCGI.
include /usr/local/etc/nginx/fastcgi.conf;

server {
listen 80;
server_name localhost;
# try_files $uri $uri/ /index.html;
location /nginx_status {
stub_status on;
access_log off;
# allow IP-OpenNMS;
# deny all;
}

location / {
index index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}

#index index.php;
root /path/to/moodle/files/that/isn't/important/here;
include php.conf;
#moodle hack
rewrite ^/file.php/(.*)$ /file.php?file=/$1 last;
rewrite ^/user/pix.php(.*)$ /user/pix.php?file=/$1 last;

# If file isn't found
if (!-e $request_filename) {
set $filephp 1;
}
# If the missing file is a php folder URL
if ($request_filename ~ "\.php/") {
set $filephp "${filephp}1";
}
# Non-existing URL based on PHP script
# Rewrite the URL to the base PHP script requesting
if ($filephp = 11) {
rewrite ^(.*).php/.*$ /$1.php last;
break;
}

}

}

-------------------------------- END nginx.conf

Here's our fastcgi.conf:
-------------------------------- BEGIN fastcgi.conf
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
--------------------------------END fastcgi.conf


Our nginx.conf also includes a php.conf file:

-------------------------------- BEGIN php.conf
fastcgi_intercept_errors on;

location ~ \.php$
{
fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

fastcgi_read_timeout 600; # Set fairly high for debugging
fastcgi_connect_timeout 180;

fastcgi_pass 127.0.0.1:9001; # Non-default port
fastcgi_index index.php;
}
-------------------------------- END php.conf

Here's the uncommented portions of our php-fpm.conf:
-------------------------------- BEGIN php-fpm.conf
[global]
[www]
listen = 127.0.0.1:9001
user = nobody
group = nobody
pm = dynamic
pm.max_children = 550
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 15
pm.max_requests = 200
pm.status_path = /status
request_slowlog_timeout = 25s
slowlog = /var/log/nginx/php-fpm.slow.log
--------------------------------END php-fpm.conf

I'll gladly post any other details that you might need to help me get this running smoother. Thanks, all!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 107
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready