2016-05-01 11 views
0

Ich habe eine WordPress-Installation auf Bitnami. Ich versuche ein CDN für den Inhalt des Ordners wp-content einzurichten. Das CDN verwendet AWS Cloudfront mit dem gesamten Inhalt des Ordners wp-content in einem S3-Bucket. Ich kann Apache nicht dazu bringen, alle Anforderungen für die Assets an das CDN umzuleiten. Ich habe einige Dinge ausprobiert, aber ich kann es einfach nicht zur Arbeit bringen.Umleiten zu CDN

Inhalt der Datei htaccess.conf.

RewriteCond %{HTTP_HOST} ^(www\.)?site.com 
RewriteCond %{REQUEST_URI} ^(.*)\.jpg$ 
RewriteCond %{REQUEST_URI} ^(.*)\.png$ 
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301] 

<IfModule mod_expires.c> 
ExpiresActive On 
ExpiresByType text/css "access 1 month" 
ExpiresByType text/html "access 1 month" 
ExpiresByType image/gif "access 1 year" 
ExpiresByType image/png "access 1 year" 
ExpiresByType image/jpg "access 1 year" 
ExpiresByType image/jpeg "access 1 year" 
ExpiresByType image/x-icon "access 1 year" 
ExpiresByType application/pdf "access 1 month" 
ExpiresByType application/javascript "access 1 month" 
ExpiresByType text/x-javascript "access 1 month" 
ExpiresByType application/x-shockwave-flash "access 1 month" 
<FilesMatch "\.(js|css)$"> 
    ExpiresActive On 
    ExpiresDefault "access plus 1 week" 
</FilesMatch> 
ExpiresDefault "access 1 month" 
</IfModule> 
# Expires Caching End # 

<Directory "/opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/akismet"> 
# Only allow direct access to specific Web-available files. 

# Apache 2.2 
<IfModule !mod_authz_core.c> 
    Order Deny,Allow 
    Deny from all 
</IfModule> 

# Apache 2.4 
<IfModule mod_authz_core.c> 
    Require all denied 
</IfModule> 

# Akismet CSS and JS 
<FilesMatch "^(form|akismet)\.(css|js)$"> 
    <IfModule !mod_authz_core.c> 
     Allow from all 
    </IfModule> 

    <IfModule mod_authz_core.c> 
     Require all granted 
    </IfModule> 
</FilesMatch> 

# Akismet images 
<FilesMatch "^(.+)\.(png|gif)$"> 
    <IfModule !mod_authz_core.c> 
     Allow from all 
    </IfModule> 

    <IfModule mod_authz_core.c> 
     Require all granted 
    </IfModule> 
</FilesMatch> 

# compression 
<ifModule mod_gzip.c> 
    mod_gzip_on Yes 
    mod_gzip_dechunk Yes 
    mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ 
    mod_gzip_item_include handler ^cgi-script$ 
    mod_gzip_item_include mime ^text/.* 
    mod_gzip_item_include mime ^application/x-javascript.* 
    mod_gzip_item_exclude mime ^image/.* 
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* 
</ifModule> 

#</ifModule> 
# BEGIN Compress text files 
<ifModule mod_deflate.c> 
<filesMatch "\.(css|js|x?html?|php)$"> 
SetOutputFilter DEFLATE 
</filesMatch> 
</ifModule> 
# END Compress text files 
</Directory> 

Inhalt von http-app.conf

<VirtualHost *:80> 
    ServerName site.com 
    ServerAlias www.site.com 
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs" 
    # Added the following 3 lines to force https 
    RewriteEngine On 
    RewriteCond %{HTTPS} !=on 
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L] 
    #RewriteRule ^wp-content/uploads/(.*)$ https://site.cloudfront.net/wp-content/uploads/$1 [P] 
    #Redirect permanent /wp-content/ https:/site.cloudfront.net/wp-content/ 
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf" 
</VirtualHost> 

<VirtualHost *:443> 
    ServerName site.com 
    ServerAlias www.site.com 
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs" 
    SSLEngine on 
    SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt" 
    SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.key" 
    SSLCACertificateFile "/opt/bitnami/apps/wordpress/conf/certs/www.site.crt" 
    Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf" 
</VirtualHost> 

Inhalt von httpd-app.conf

RewriteCond %{HTTP_HOST} ^(www\.)?site.com 
RewriteCond %{REQUEST_URI} ^(.*)\.jpg$ 
RewriteCond %{REQUEST_URI} ^(.*)\.png$ 
RewriteRule ^/(.*)$ https://site.cloudfront.net/$1 [NC,NE,R=301] 

<IfDefine USE_PHP_FPM> 
    <Proxy "unix:/opt/bitnami/php/var/run/wordpress.sock|fcgi://wordpress-fpm" timeout=300> 
    </Proxy> 
</IfDefine> 

<Directory "/opt/bitnami/apps/wordpress/htdocs"> 
# Added +Includes for CDN testing. KA 
    Options +MultiViews +FollowSymLinks +Includes 
# Change from None to All. KA 
    AllowOverride All 
    <IfVersion <2.3> 
     Order allow,deny 
     Allow from all 
    </IfVersion> 
    <IfVersion >= 2.3> 
     Require all granted 
    </IfVersion> 

    <IfDefine USE_PHP_FPM> 
     <FilesMatch \.php$> 
     SetHandler "proxy:fcgi://wordpress-fpm/" 
     </FilesMatch> 
    </IfDefine> 


    RewriteEngine On 
# Do not touch the lines below. Added for redierect to www. KA 
    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
    #RewriteBase /wordpress/ 
    RewriteRule ^index\.php$ - [S=1] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . index.php [L] 
</Directory> 

Include "/opt/bitnami/apps/wordpress/conf/htaccess.conf" 

Wenn jemand merkt jeder redundanten Code das ist mir dann testen, um zu Umleitungen mit Bezug zu bekommen das funktioniert.

Ich kann auf den Inhalt des S3-Buckets und der Cloudfront-URL außerhalb der Site ohne Probleme zugreifen.

Irgendwelche Lösungen oder Zeiger in die richtige Richtung würden helfen.

Danke!

+0

Entschuldigung, ich werde meine Antwort als Antwort für die Codeformatierung schreiben. – janicehoplin

Antwort

0

Ich bin mir nicht sicher, ob dies wird Ihnen helfen, aber so weit wie die Umleitung geht:

Wenn ich auf https aus der HTTP-Version von meiner Seite leite ich diese Zeile in meiner apache2.conf Datei:

Redirect "/" "https://www.version.of.my.site" 

Ich bemerkte, dass Ihre Redirect-Zeilen in Ihrer http-app.conf auskommentiert sind.

+0

Ich habe versucht, wie eine 100 verschiedene Kombinationen, aber keiner von ihnen hat für mich bisher funktioniert. Die Seite leitet auf https sogar von http mit dem, was ich gerade habe. – naerak

+0

@naerak Gibt es ein Forum für das CDN, das Sie verwenden? Vielleicht wären sie hilfreicher. Auch habe ich nicht vorgeschlagen, das zu verwenden, was ich oben für das Umleiten von http zu https bekannt gab. Ich habe gesagt, dass ich so umleitung und vielleicht können Sie die gleiche Codezeile verwenden, um in Ihrer Apache-Konfigurationsdatei umzuleiten. Ich sehe es oben in Ihrem virtuellen Host, aber es ist auskommentiert. – janicehoplin