I'm trying to configure nginx to run a moodle website in parallel to a django one and a jellyfin one. My domain name is www.example.com
and I would like to set everything that ends with www.example.com/moodle
to the moodle site and all non-moodle pages to be handled by django and jellyfin.
The following nginx
configuration worked for django and jellyfin:
upstream champhy {
server unix:/mnt/data1/django_apps/champhy/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80 default_server;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
server_name www.example.com; # managed by Certbot
location /jellyfin {
return 302 $scheme://$host/jellyfin/;
}
location /jellyfin/ {
proxy_pass http://localhost:8096/jellyfin/;
proxy_pass_request_headers on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_buffering off;
}
location /media {
alias /mnt/data1/data;
client_max_body_size 50m;
}
location /static {
client_max_body_size 50m;
alias /mnt/data1/django_static/champhy;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
}
}
I read a lot of documentation about moodle but I can't figure out how to make it work. I'm very new to php and according to this, this and that I tried to add new locations like this:
location / {
try_files $uri $uri/ =404;
}
location /dataroot/ {
internal;
alias /var/www/html/moodledata/;
}
location ~ /moodle/(.\+.php(/|$) {
fastcgi_split_path_info ^moodle/(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
But after a lot of effort I keep on failing. Note that when I disable django and jellyfin and I run only moodle on www.example.com
, it works. Please, help me, I'm a teacher who want to get ready for his students before the coming lockdown... thx