Skip to content

Instantly share code, notes, and snippets.

@Thirdwrist
Last active July 2, 2020 07:33
Show Gist options
  • Save Thirdwrist/0c32a1460ef8a62bd30fc8962c8f47ee to your computer and use it in GitHub Desktop.
Save Thirdwrist/0c32a1460ef8a62bd30fc8962c8f47ee to your computer and use it in GitHub Desktop.
DirectoryIndex index.html index.php
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
# If installed in local or under a path say /getteachrfarid /: (otherwise, doesn't need RewriteBase)
RewriteBase /
RewriteRule ^(docs)($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^img/([a-zA-Z_]*)/([a-zA-Z_]*)/(.*)$ server/php/image.php?size=$1&model=$2&filename=$3 [NC]
RewriteRule ^download/([a-zA-Z0-9_.]*)/([a-zA-Z0-9_.]*)$ server/php/download.php?hash=$1&type=$2 [NC]
RewriteRule ^client/download/([0-9]*)/([a-zA-Z0-9_\.]*)/([0-9]*)$ server/php/plugins/DownloadableFileLessons/download.php?id=$1&hash=$2&timestamp=$3 [NC]
RewriteRule ^video/([a-zA-Z_]*)/([0-9]*)/([a-zA-Z0-9_\.]*)/([0-9]*)$ server/php/plugins/VideoLessons/play_video.php?type=$1&id=$2&hash=$3&timestamp=$4 [NC]
RewriteRule ^audio/([a-zA-Z_]*)/([0-9]*)/([a-zA-Z0-9_\.]*)/([0-9]*)$ server/php/plugins/AudioLessons/play_audio.php?type=$1&id=$2&hash=$3&timestamp=$4 [NC]
#RewriteRule ^api/(.*)$ server/php/R/r.php?_url=$1 [QSA,L]
RewriteRule ^api/(.*)$ server/php/Slim/public/index.php [QSA,L]
RewriteRule ^ipn/receiver_account_ipn/([0-9]*)/users/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ server/php/plugins/Payout/receiver_account_ipn.php?gateway_id=$1&user_id=$2&hash=$3 [NC]
RewriteRule ^ipn/process_ipn/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ server/php/plugins/SudoPay/process_ipn.php?course_user_id=$1&hash=$2 [NC]
RewriteRule ^certificate/([0-9]*)/([a-zA-Z0-9_\.]*)/([a-zA-Z]*)$ server/php/certificate.php?course_user_id=$1&hash=$2&type=$3 [NC]
RewriteRule ^ipn/paypal_process_ipn/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ server/php/plugins/PayPal/paypal_payment_process_ipn.php?course_user_id=$1&hash=$2 [NC]
RewriteRule ^ipn/process_ipn/user_subscription_logs/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ server/php/plugins/SudoPay/process_ipn.php?user_subscription_logs_id=$1&hash=$2 [NC]
RewriteRule ^ipn/paypal_process_ipn/user_subscriptions/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ server/php/plugins/PayPal/paypal_subscription_process_ipn.php?user_subscription_id=$1&hash=$2 [NC]
RewriteRule ^download_resume/([a-zA-Z_]*)/([0-9]*)/(.*)$ /server/php/download_resume.php?model=$1&id=$2&filename=$3 [NC]
RewriteRule ^download_message_content/([a-zA-Z_]*)/([0-9]*)/(.*)$ /server/php/download_resume.php?model=$1&id=$2&filename=$3 [NC]
RewriteRule ^download/([0-9]*)/([a-zA-Z0-9_\.]*)/([a-zA-Z0-9_\.]*)$ server/php/download.php?id=$1&hash=$2&type=$3 [NC]
# RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
# RewriteRule ^$ server/php/plugins/SEO/seo.php$1 [QSA,L]
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit/1.1|Facebot|Twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|Pinterest|Google.*snippet|/externalhit_uatext/|Slackbot|Slack-ImgProxy|Slackbot-LinkExpanding|Site\ Analyzer|SiteAnalyzerBot|Viber|Whatsapp|Telegram [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
RewriteRule ^$ server/php/plugins/SEO/seo.php$1 [QSA,L]
RewriteRule ^$ client/build/[QSA,L]
RewriteRule ^docs$ client/build/docs/index.html [QSA,L]
RewriteRule ^ag-admin$ client/build/ag-admin/index.html [QSA,L]
RewriteRule ^(templates-app.js|templates-common.js)$ client/build/$1 [QSA,L]
RewriteRule ^(assets|api_explorer|docs|ag-admin|admin|vendor|src)/(.*)$ client/build/$1/$2 [QSA,L]
RewriteRule ^favicon.ico$ client/favicon.ico [L]
RewriteRule ^apple-touch-icon(.*)$build/ client/build/apple-touch-icon$1 [L]
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ client/build/index.html [L]
</IfModule>
@Thirdwrist
Copy link
Author

nginx-config.conf

server {
listen 80;
server_name tef-lms-api.localhost tef-lms-api.demo.agriya.com;

root /usr/share/nginx/html/tef-lms-api;
try_files $uri $uri/ /index.html;

gzip on;
gzip_disable "msie6";

gzip_comp_level 6;
# gzip_comp_level 9;
gzip_min_length  1100;
gzip_buffers 16 8k;
gzip_proxied any;
# gzip_http_version 1.1;
gzip_types       text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;

rewrite ^/api/ /server/php/Slim/public/index.php;
rewrite ^/api_explorer/api/ /server/php/Slim/public/index.php;

if ($args ~ "_escaped_fragment_") {
        rewrite ^ /server/php/plugins/SEO/seo.php?path=$1 last;
    }

rewrite ^/video/([a-zA-Z_]*)/([0-9]*)/([a-zA-Z0-9_\.]*)/([0-9]*)$ /server/php/plugins/VideoLessons/play_video.php?type=$1&id=$2&hash=$3&timestamp=$4 last;
rewrite ^/audio/([a-zA-Z_]*)/([0-9]*)/([a-zA-Z0-9_\.]*)/([0-9]*)$ /server/php/plugins/AudioLessons/play_audio.php?type=$1&id=$2&hash=$3&timestamp=$4 last;
rewrite ^/client/download/([0-9]*)/([a-zA-Z0-9_\.]*)/([0-9]*)$ /server/php/plugins/DownloadableFileLessons/download.php?id=$1&hash=$2&timestamp=$3 last;
rewrite ^/certificate/([0-9]*)/([a-zA-Z0-9_\.]*)/([a-zA-Z]*)$ /server/php/certificate.php?course_user_id=$1&hash=$2&type=$3 last;
rewrite ^/download/([a-zA-Z0-9_\.]*)$ /server/php/download.php?hash=$1 last;
rewrite ^/ipn/receiver_account_ipn/([0-9]*)/users/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ /server/php/plugins/Payout/receiver_account_ipn.php?gateway_id=$1&user_id=$2&hash=$3 last;
rewrite ^/download/([a-zA-Z0-9_\.]*)/([a-zA-Z0-9_\.]*)$ /server/php/download.php?hash=$1&type=$2 last;
rewrite ^/download/([0-9]*)/([a-zA-Z0-9_\.]*)/([a-zA-Z0-9_\.]*)$ /server/php/download.php?id=$1&hash=$2&type=$3 last;
rewrite ^/ipn/process_ipn/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ /server/php/plugins/SudoPay/process_ipn.php?course_user_id=$1&hash=$2 last;
rewrite ^/ipn/paypal_process_ipn/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ /server/php/plugins/PayPal/paypal_payment_process_ipn.php?course_user_id=$1&hash=$2 last;

rewrite ^/ipn/process_ipn/user_subscription_logs/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ /server/php/plugins/SudoPay/process_ipn.php?user_subscription_logs_id=$1&hash=$2 last;
rewrite ^/ipn/paypal_process_ipn/user_subscriptions/([0-9]*)/hash/([a-zA-Z0-9_\.]*)$ /server/php/plugins/PayPal/paypal_subscription_process_ipn.php?user_subscription_id=$1&hash=$2 last;
rewrite ^/download_message_content/([a-zA-Z_]*)/([0-9]*)/(.*)$ /server/php/download_resume.php?model=$1&id=$2&filename=$3 last;
rewrite ^/download_resume/([0-9]*)/([a-zA-Z0-9_\.]*)/([a-zA-Z0-9_\.]*)/([0-9]*)$ /server/php/download.php?id=$1&hash=$2&type=$3&foreign_id=$4 last;

location / {
	if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|yandex|yeti|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|developers\.google\.com") {
	    rewrite ^ /server/php/plugins/SEO/seo.php?path=$1;
	}
	root /usr/share/nginx/html/tef-lms-api/client/build;
	 	try_files $uri $uri/ /index.html;

	index index.php index.html index.htm;
}
location ~ /api_explorer {
	root /usr/share/nginx/html/tef-lms-api;
}

location ~ \.php$ {
	try_files $uri =404;
	include fastcgi_params;
	fastcgi_pass    unix:/run/php/php5.6-fpm.sock;
	fastcgi_index   index.php;
	fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(jpg|jpeg|gif|png|bmp|ico|css|js) {
	root /usr/share/nginx/html/tef-lms-api/client/build;
	 	try_files $uri $uri/ /index.html;

	if (-f $request_filename) {
		break;
	}
	rewrite ^/img/([a-zA-Z_]*)/([a-zA-Z_]*)/(.*)$ /server/php/image.php?size=$1&model=$2&filename=$3 last;
        auth_basic off;
	add_header        Cache-Control public;
	add_header        Cache-Control must-revalidate;
	expires           7d;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment