First stop and disable apache
$ sudo systemctl stop httpd
$ sudo systemctl disable httpd
install nginx
$ sudo yum install epel-release
$ sudo yum install nginx
$ sudo systemctl start nginx
$ sudo systemctl enable nginx
http://ipaddress/ should show nginx default page
The default path root for nginx /usr/share/nginx/html
configure php settings
$ sudo vi /etc/php.ini
cgi.fix_pathinfo=0
make sure php-fpm is installed
$ sudo yum install php-fpm
$ sudo vi /etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nobody
listen.group = nobody
user = nginx
group = nginx
security.limit_extensions = .php .php3 .php4 .php5
$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpm
add the below script as new default config file
$ sudo vi /etc/nginx/conf.d/default.conf
server { listen 80; server_name ip_address; # note that these lines are originally from the "location /" block root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location /dataroot/ { internal; alias /var/moodledata/; # ensure the path ends with / } location /cachedir/ { internal; alias /var/moodledata/cache/; # ensure the path ends with / } location /localcachedir/ { internal; alias /var/moodledata/localcache/; # ensure the path ends with / } location /tempdir/ { internal; alias /var/moodledata/temp/; # ensure the path ends with / } location /filedir/ { internal; alias /var/moodledata/filedir/; # ensure the path ends with / }
if moodle is still in apache server copy it under nginx
$ sudo cp -R /var/www/html/moodle/* /usr/share/nginx/html/
enable nginx settings in moodle config file
$ sudo vi /usr/share/nginx/html/config.php
//enabled by Mehmet Sen $CFG->xsendfile = 'X-Accel-Redirect'; // Nginx {@see http://wiki.nginx.org/XSendfile} // If your X-Sendfile implementation (usually Nginx) uses directory aliases specify them // in the following array setting: $CFG->xsendfilealiases = array( '/dataroot/' => $CFG->dataroot, '/cachedir/' => '/var/moodledata/cache', // for custom $CFG->cachedir locations '/localcachedir/' => '/var/moodledata/localcache', // for custom $CFG->localcachedir locations '/tempdir/' => '/var/moodledata/temp', // for custom $CFG->tempdir locations '/filedir' => '/var/moodledata/filedir', // for custom $CFG->filedir locations );
restart nginx
$ sudo systemctl restart nginx