Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor and fix nginx/htaccess config examples #302

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions inc/setup/cachify.apc.htaccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
/* Quit */
defined( 'ABSPATH' ) || exit;

$beginning = '<Files index.php>
php_value auto_prepend_file ';

$ending = '/cachify/apc/proxy.php
</Files>';
$htaccess = '<Files index.php>
php_value auto_prepend_file ' . WP_PLUGIN_DIR . '/cachify/apc/proxy.php
</Files>';

// phpcs:disable Squiz.PHP.EmbeddedPhp
?>
Expand All @@ -21,10 +19,5 @@
<p><?php esc_html_e( 'Please add the following lines to your .htaccess file', 'cachify' ); ?></p>

<textarea rows="5" class="large-text code cachify-code" name="code" readonly><?php
printf(
'%s%s%s',
esc_html( $beginning ),
esc_html( WP_PLUGIN_DIR ),
esc_html( $ending )
);
?></textarea>
echo esc_html( $htaccess );
?></textarea>
17 changes: 5 additions & 12 deletions inc/setup/cachify.apc.nginx.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
/* Quit */
defined( 'ABSPATH' ) || exit;

$beginning = 'location ~ .php {
$nginx_conf = 'location ~ .php {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
<strong>fastcgi_param PHP_VALUE auto_prepend_file=';

$ending = '/cachify/apc/proxy.php</strong>;
fastcgi_param PHP_VALUE auto_prepend_file=' . WP_PLUGIN_DIR . '/cachify/apc/proxy.php;
location ~ /wp-admin/ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
<strong>fastcgi_param PHP_VALUE auto_prepend_file=</strong>;
fastcgi_param PHP_VALUE auto_prepend_file=;
}
}';

Expand All @@ -29,12 +27,7 @@
<p><?php esc_html_e( 'Please add the following lines to your nginx PHP configuration', 'cachify' ); ?></p>

<textarea rows="13" class="large-text code cachify-code" name="code" readonly><?php
printf(
'%s%s%s',
esc_html( $beginning ),
esc_html( WP_PLUGIN_DIR ),
esc_html( $ending )
);
?></textarea>
echo esc_html( $nginx_conf );
?></textarea>

<small>(<?php esc_html_e( 'You might need to adjust the non-highlighted lines to your needs.', 'cachify' ); ?>)</small>
50 changes: 19 additions & 31 deletions inc/setup/cachify.hdd.htaccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
/* Quit */
defined( 'ABSPATH' ) || exit;

$beginning = '# BEGIN CACHIFY
&lt;IfModule mod_rewrite.c&gt;
# ENGINE ON
$htaccess = '# BEGIN CACHIFY
<IfModule mod_rewrite.c>;
RewriteEngine on
# set hostname directory
Expand All @@ -24,35 +23,31 @@
RewriteRule .* - [E=CACHIFY_DIR:%{REQUEST_URI}]
RewriteCond %{REQUEST_URI} ^$
RewriteRule .* - [E=CACHIFY_DIR:/]
{{GZIP}}
# Main Rules
RewriteCond %{HTTP_ACCEPT} .*text/html.*
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-content/cache)/.*
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond ';
';

$gzip = '';
if ( Cachify_HDD::is_gzip_enabled() ) {
$gzip = '
$htaccess .= '
# gzip
RewriteRule .* - [E=CACHIFY_SUFFIX:]
&lt;IfModule mod_mime.c&gt;
<IfModule mod_mime.c>;
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=CACHIFY_SUFFIX:.gz]
AddType text/html .gz
AddEncoding gzip .gz
&lt;/IfModule&gt;
</IfModule>;
';
}
$beginning = str_replace( '{{GZIP}}', $gzip, $beginning );

$middle = '/cache/cachify/%{ENV:CACHIFY_HOST}%{ENV:CACHIFY_DIR}index.html%{ENV:CACHIFY_SUFFIX} -f
RewriteRule ^(.*) ';

$ending = '/cache/cachify/%{ENV:CACHIFY_HOST}%{ENV:CACHIFY_DIR}index.html%{ENV:CACHIFY_SUFFIX} [L]
&lt;/IfModule&gt;
$htaccess .= '
# Main Rules
RewriteCond %{HTTP_ACCEPT} .*text/html.*
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-content/cache)/.*
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond ' . WP_CONTENT_DIR . '/cache/cachify/%{ENV:CACHIFY_HOST}%{ENV:CACHIFY_DIR}index.html%{ENV:CACHIFY_SUFFIX} -f
RewriteRule ^(.*) ' . wp_make_link_relative( content_url() ) . '/cache/cachify/%{ENV:CACHIFY_HOST}%{ENV:CACHIFY_DIR}index.html%{ENV:CACHIFY_SUFFIX} [L]
</IfModule>;
# END CACHIFY';

// phpcs:disable Squiz.PHP.EmbeddedPhp
Expand All @@ -62,15 +57,8 @@
<p><?php esc_html_e( 'Please add the following lines to your .htaccess file', 'cachify' ); ?></p>

<textarea rows="16" class="large-text code cachify-code" name="code" readonly><?php
printf(
'%s%s%s%s%s',
esc_html( $beginning ),
esc_html( WP_CONTENT_DIR ),
esc_html( $middle ),
esc_html( wp_make_link_relative( content_url() ) ),
esc_html( $ending )
);
?></textarea>
echo esc_html( $htaccess );
?></textarea>

<h3><?php esc_html_e( 'Notes', 'cachify' ); ?></h3>
<ol>
Expand All @@ -83,7 +71,7 @@
<li>
<?php esc_html_e( 'If there are partial errors in the redirects within the blog, the shutdown of the Apache Content Cache can help:', 'cachify' ); ?><br />
<pre>&lt;IfModule mod_cache.c&gt;
CacheDisable /
CacheDisable /
&lt;/IfModule&gt;</pre>
</li>
<li>
Expand Down
2 changes: 2 additions & 0 deletions inc/setup/cachify.hdd.nginx.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
<p><?php esc_html_e( 'Please add the following lines to your nginx.conf', 'cachify' ); ?></p>

<textarea rows="16" class="large-text code cachify-code" name="code" readonly>
<?php if ( Cachify_HDD::is_gzip_enabled() ) : ?>
## GZIP
gzip_static on;

<?php endif; ?>
## CHARSET
charset utf-8;

Expand Down
3 changes: 0 additions & 3 deletions inc/setup/cachify.memcached.nginx.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<p><?php esc_html_e( 'Please add the following lines to your nginx.conf', 'cachify' ); ?></p>

<textarea rows="16" class="large-text code cachify-code" name="code" readonly>
## GZIP
gzip_static on;

## CHARSET
charset utf-8;

Expand Down