#gzip on; upstream php { server unix:/var/run/php/php7.4-fpm.sock; } include /etc/nginx/conf.d/*.conf; }
sites.conf file:
server { #Version 2.0 #1. IP Restrictions #allow 14.201.246.57; #deny all;
client_max_body_size 20M; access_log /srv/www/lms.dchstudio.com.au/logs/access.log; error_log /srv/www/lms.dchstudio.com.au/logs/error.log; server_name www.lms.dchstudio.com.au lms.dchstudio.com.au;# is your website name
root /srv/www/lms.dchstudio.com.au/public_html;
index index.html index.htm index.php;
# We check IP Address against the whitelists #allow 14.201.246.57;#Testing #deny all; # Moodle big fix_rewrite rule rewrite ^/(.*\.php)(/)(.*)$ /$1?file=/$3 last; #Exceptions location = /favicon.ico { access_log off; log_not_found off; expires max; } location = /robots.txt { access_log off; log_not_found off; }
# Cache Static Files For As Long As Possible location ~*\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; }
# pass the PHP scripts to FPM socket location ~ [^/]\.php(/|$) { try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
# Php handler try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini fastcgi_pass php; fastcgi_param SCRIPT_FILENAME /srv/www/blog.bjdch.org/public_html$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /srv/www/blog.bjdch.org/public_html; # send bad requests to 404 fastcgi_intercept_errors on; include fastcgi_params;
}
#wp-admin IP and Password Protection
location ~* /wp-admin/.*\.php$ {
# We check IP Address against the whitelists # allow 14.201.246.57;#Testing # deny all;
# Then we check the password auth_basic “All of the user access are recorded. Authorised Personnel Only!”; auth_basic_user_file /srv/www/blog.bjdch.org/logs/.htpasswd;
# Php handler try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini fastcgi_pass php;
fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/www/blog.bjdch.org/public_html/$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /srv/www/blog.bjdch.org/public_html; # send bad requests to 404 fastcgi_intercept_errors on; include fastcgi_params; } }
# Cache Static Files For As Long As Possible location ~*\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|$ { access_log off; log_not_found off; expires max; } # Security Settings For Better Privacy Deny Hidden Files location ~ /\. { deny all; access_log off; log_not_found off; }
# Disallow PHP In Upload Folder location /wp-content/uploads/ { location ~ \.php$ { deny all; } } # Return 403 Forbidden For readme.(txt|html) or license.(txt|html) if ($request_uri ~* “^.+(readme|license)\.(txt|html)$”) { return 403; }
#WP Rewrite location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. #try_files $uri $uri/ =404; #index index.html index.htm index.php;
16/04/2024
NGINX config with WordPress and Moodle
By dch1 in Just Notes No Comments Tags: Moodle, Nginx, VPS
Working config for Moodle config:
nginx.conf file:
sites.conf file:
Working config for WordPress: