Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save developerck/1e50fb8cf7d473de7bf116204f25c4ef to your computer and use it in GitHub Desktop.
Save developerck/1e50fb8cf7d473de7bf116204f25c4ef to your computer and use it in GitHub Desktop.
nginx for moodle 2.7 with caching and ssl and differnet caching pattern for different media
server {
listen 443 ssl;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
// ssl cert
ssl_certificate /etc/ssl/certs/nginx/client_ssl.chained.crt;
ssl_certificate_key /etc/ssl/certs/nginx/client_ssl.key;
server_name client.com; // servername
access_log /var/log/nginx/client.com-access_log;
error_log /var/log/nginx/client.com-error_log;
root /var/www/html/client/; // client docuemnt root
index index.html index.php ;
try_files $uri $uri/ =404;
add_header 'Access-Control-Allow-Origin' *;
location / {
if (-d $request_filename) {
rewrite [^/]$ $scheme://$http_host$uri/ permanent;
}
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;
#caching
proxy_buffering on;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_cache reverse_cache;
proxy_cache_valid 30s;
proxy_no_cache $cookie_PHPSESSID;
proxy_cache_bypass $cookie_PHPSESSID;
proxy_cache_bypass $cookie_MoodleSession;
proxy_cache_key "$scheme$host$request_uri";
add_header X-Cache $upstream_cache_status;
proxy_pass "http://localhost:8001";
}
## dynamic content
location ~ /pluginfile\.php/ {
if (-d $request_filename) {
rewrite [^/]$ $scheme://$http_host$uri/ permanent;
}
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;
#caching
proxy_buffering on;
add_header X-PCache $upstream_cache_status;
expires -1d;
proxy_pass "http://localhost:8001";
}
## theme
location ~* /theme/(image|styles|javascript|jquery)\.php/ {
if (-d $request_filename) {
rewrite [^/]$ $scheme://$http_host$uri/ permanent;
}
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;
#caching
proxy_buffering on;
proxy_ignore_headers Cache-Control;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_cache reverse_cache;
proxy_cache_valid 200 120m;
expires 1d;
proxy_cache_key "$scheme$host$request_uri";
add_header X-TCache $upstream_cache_status;
proxy_pass "http://localhost:8001";
}
## satic
location ~* \.(js|jpg|png|gif|jpeg|css|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {
if (-d $request_filename) {
rewrite [^/]$ $scheme://$http_host$uri/ permanent;
}
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;
#caching
proxy_buffering on;
proxy_ignore_headers Cache-Control;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_cache reverse_cache;
proxy_cache_valid 200 120m;
expires 1d;
proxy_cache_key "$scheme$host$request_uri";
add_header X-SCache $upstream_cache_status;
proxy_pass "http://localhost:8001";
}
autoindex off;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment