Skip to content

Instantly share code, notes, and snippets.

@anushshukla
Created January 23, 2023 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anushshukla/a6fa0bff23ccf53ad75626600bcb9cb6 to your computer and use it in GitHub Desktop.
Save anushshukla/a6fa0bff23ccf53ad75626600bcb9cb6 to your computer and use it in GitHub Desktop.
Apache Configurations
Define domain ultimate-local.com
Define abs_path /mnt/d/www/${domain}
SSLCertificateFile ${abs_path}/${domain}.crt
SSLCertificateKeyFile ${abs_path}/${domain}.key
<Directory ${abs_path}>
# all | none | -Indexes FollowSymLinks MultiViews Includes
AllowOverride all
# all | none | AuthConfig Indexes FollowSymLinks
# Order Deny,Allow
# Allow from all
Require all granted
</Directory>
<Directory ${abs_path}/public>
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -Indexes -MultiViews +Includes +FollowSymLinks
</IfModule>
RewriteEngine On
# RewriteBase /
# Conditions for localhost
# RewriteCond %{HTTP_HOST} == localhost
# RewriteCond %{HTTP_HOST} == 127.0.0.1
# RewriteCond %{REMOTE_ADDR} == 127.0.0.1
# RewriteCond %{REMOTE_ADDR} == ::1
# http TO https REDIRECT RULE STARTS HERE
## checks if no https present
RewriteCond %{HTTPS} off
RewriteCond %{HTTPS} !on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# http TO https REDIRECTS ENDS HERE
# non www (NAKED DOMAIN) TO www REDIRECT RULE STARTS HERE
## checks if no subdomain present
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
## checks if www not present immediately after the http or https but before the domain name
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# non www (NAKED DOMAIN) TO www REDIRECTS ENDS HERE
# TRAILING SLASHES REDIRECT RULE IF NOT A FOLDER STARTS HERE
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# TRAILING SLASHES REDIRECT RULE IF NOT A FOLDER ENDS HERE
# AVOID INFINTIE REDIRECTION
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# FRONT CONTROLLER HANDLE REDIRECT RULES STARTS HERE
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# FRONT CONTROLLER HANDLE RULES ENDS HERE
ReadmeName footer.html
</IfModule>
# <If "%{HTTP_HOST} =='localhost'">
# ErrorDocument 400 http://www.aura-fx.com/403
ErrorDocument 400 ${abs_path}/server-error-views/400.html
ErrorDocument 401 ${abs_path}/server-error-views/401.html
ErrorDocument 403 ${abs_path}/server-error-views/403.html
ErrorDocument 404 ${abs_path}/server-error-views/404.html
ErrorDocument 405 ${abs_path}/server-error-views/405.html
ErrorDocument 408 ${abs_path}/server-error-views/408.html
ErrorDocument 410 ${abs_path}/server-error-views/410.html
ErrorDocument 411 ${abs_path}/server-error-views/411.html
ErrorDocument 412 ${abs_path}/server-error-views/412.html
ErrorDocument 413 ${abs_path}/server-error-views/413.html
ErrorDocument 414 ${abs_path}/server-error-views/414.html
ErrorDocument 415 ${abs_path}/server-error-views/415.html
ErrorDocument 500 ${abs_path}/server-error-views/500.html
ErrorDocument 501 ${abs_path}/server-error-views/501.html
ErrorDocument 502 ${abs_path}/server-error-views/502.html
ErrorDocument 503 ${abs_path}/server-error-views/503.html
ErrorDocument 506 ${abs_path}/server-error-views/506.html
# </If>
# BEGIN leaverage caching
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|txt|html|x-html|php|css|xml|js|woff|ttf|svg|eot)(\.gz)?$">
# Expires Headers - 2678400s = 31 days
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 7200 seconds"
ExpiresByType image/gif "access plus 2678400 seconds"
ExpiresByType image/jpeg "access plus 2678400 seconds"
ExpiresByType image/png "access plus 2678400 seconds"
ExpiresByType text/css "access plus 518400 seconds"
ExpiresByType text/javascript "access plus 2678400 seconds"
ExpiresByType application/x-javascript "access plus 2678400 seconds"
</IfModule>
# Cache Headers
<IfModule mod_headers.c>
# Cache specified files for 31 days
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=2678400, public"
#Header set Expires "Sun, 27 May 2012 00:00:00 GMT"
#Header unset ETag
</filesmatch>
# Cache HTML files for a couple hours
<filesmatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
# Cache PDFs for a day
<filesmatch "\.(pdf)$">
Header set Cache-Control "max-age=86400, public"
</filesmatch>
# Cache Javascripts for 31 days
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=2678400, private"
</filesmatch>
</IfModule>
FileETag None
</FilesMatch>
# END leaverage caching
# BEGIN (GZIP) Compress text files
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
<filesMatch "\.(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# END (GZIP) Compress text files
</Directory>
<VirtualHost *:80>
DocumentRoot ${abs_path}/public
Redirect / https://www.${domain}
</VirtualHost>
<VirtualHost *:80 *:443>
ServerAdmin admin@${domain}
DocumentRoot ${abs_path}/public
ServerSignature Off
ServerName ${domain}
ServerAlias www.${domain}
# www.ultimate-local.in
# ultimate-local.in
# www.ultimate-local.co.in
# ultimate-local.co.in
# ultimate-local.org
# www.ultimate-local.org
# www.ultimate-local.gov.in
# ultimate-local.gov.in
# ProxyPreserveHost Off
# ProxyPass /proxytest "http://localhost:9000"
# ProxyPassReverse /proxytest "http://localhost:9000"
# SSL CONFIG STARTS HERE
SSLEngine on
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
# SSL CONFIG ENDS HERE
# LOG DIRECTORIES STARTS HERE
<IfModule mod_ssl.c>
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b" common
ErrorLog “|/usr/bin/cronolog ${abs_path}/logs/apache-error.log”
LogLevel debug
CustomLog “|/usr/bin/cronolog ${abs_path}/logs/apache-access.log” common
TransferLog “|/usr/bin/cronolog ${abs_path}/logs/apache-transfer.log”
</IfModule>
</IfModule>
# LOG DIRECTORIES ENDS HERES
Alias /error/include/ ${abs_path}/logs/
<IfModule mod_php5.c>
php_flag html_errors on
php_flag log_errors on
php_flag display_errors on
php_value upload_max_filesize 5M
php_value error_reporting 2147483647
php_value upload_tmp_dir “|/usr/bin/cronolog ${abs_path}/tmp/”
php_value error_log ${abs_path}/logs/php-error.log
# php_value curl.cainfo ${abs_path}/logs/caert.pem
</IfModule>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment